User:Puxlit/SW-js Proposal

Motivation

 * sometimes, we'd like to rewrite ResourceLoader URLs (e.g. FANSUN and GlobalChatJS), but due to load order/races, it's not easy to do this in a foolproof manner from our regular scripts
 * service workers permit us to rewrite such URLs (via the  event)
 * however, we can only have at most one service worker per scope
 * consequently, we'd like some sort of library that permits the composition of multiple faux service workers

Design Requirements

 * the library must not attempt to register a service worker if one is already registered
 * this ensures that, should Wikia ever set up an "official" service worker, we won't conflict with them
 * to permit upgrading from scripts that are already using service workers (like GlobalChatJS), the library's initialization function may take an optional parameter describing a URL pattern for which it is acceptable for the library to install over
 * the library should guarantee isolation for script load provenance
 * in other words, if a script that's loaded via a user's personal JS pulls in a faux service worker, then it should no longer operate once the user logs out
 * alternatively, if a script that pulls in a faux service worker is removed from ImportJS, then it should not longer operate
 * the library may guarantee isolation of faux service worker lifecycle events
 * in other words, it would be nice (though not strictly necessary for a barebones implementation) if exceptions thrown during the  and   events for a given faux service worker did not affect other faux service workers
 * this could be achieved by shimming/emulating these particular events
 * the library may provide declarative APIs for common use cases (for convenience)
 * in other words, rewriting URLs should probably be given special treatment that elides the need for providing a bona fide faux service worker script

Acknowledgements
Thanks to the following individuals for their design input: Dorumin and Hypirae.