In reply to Weston Ruter.

Pete, yep you're right about SPAs, but it's no different than for non-SPAs sites, same strategy will work. The strategy that I describe will dynamically generate an actual .js file that then can be referenced statically (it is not generated each time you request it, but only once before deploying the application), so from that side it is not an issue. Then, the greatest performance gain that can be achieved through SW is precaching assets: it's very easy to implement through hooks, and it allows sites to be loaded in no time after the 2nd load (loading assets takes a huge chunk of the page loading time... if these can be preloaded, we got a huge performance bump there). And regarding notifications, they can perfectly be implemented through some generic solution that works for the majority of the cases too.

I have no doubt that that it is possible to create a generic solution that covers most of the cases for which there is an immediate, easy to achieve gain. And for everything else, as long as we generate the service-worker.js file from a PHP template, then customized functionality can also be incorporated, implemented at the theme level. So far, at least, it has worked pretty well on my site.

I do not doubt that a plugin can provide these easy gains for the WordPress ecosystem too.