In reply to Peter Shaw.

2. Service workers are powerful, flexible and there is no right way. So having a service worker api is not a good idea imo.

This may be true, but there is a workaround to this issue that can work for a majority of plugins out there: a master plugin can implement snippets of standard SW functionality (eg: precache assets, store page in SW cache after visiting, etc) that both the theme and other plugins can subscribe to through standard WordPress hooks (eg: any plugin can hook in its resources to precache, etc). Then, from a template coded in PHP, we can dynamically generate a single service-worker.js file from the input of several plugins. I wrote about this approach in detail here.

This strategy is a trade-off: while plugins don't get to code their own more specific/customized functionalities, the general use cases are covered; it is losing a bit of flexibility, but it is still very powerful and makes it very easy for any plugin to benefit from it. So, in a way, you can have a SW API that will benefit most cases out there.