In reply to Weston Ruter.

Rick, no I'm not proposing to have different service workers on different URLs for the same site, that wouldn't work in my opinion. What I'm suggesting is a way in which the final service-worker.js file, which is unique, is generated dynamically from a PHP process (done only once, just before deploying the site), and that plugins are allowed to output their code into it through standard WordPress hooks. I implemented this approach and it works fine for me. The template to generate the service-worker.js file I implemented is this one, in which the values to replace variables (such as ${cacheItems}) are filled by plugins through hooks.

In that template there have been coded a few of the general-use functionalities for SW: precache assets, and different strategies for caching pages (taken from Jake Archibald's offline cookbook.) This same logic can be perfectly put in a plugin, shipping with many of these functionalities, and then at the theme level it can be configured which ones are needed, and only those will be printed on the generated service-worker.js file.