Osvaldas Valutis from kollegorna.se has written an in-depth article on Service Workers
We’ve learned there quite a few gotchas to grasp in order to get Service Worker working correctly…
Comes with some solid advice and lots of code snippets.
One thing mentioned, that hadn’t crossed my mind before at all, is that it’s perfectly possible to “just” use ES2015 in your service worker:
It is completely safe to use the renewed JavaScript syntax in your
serviceworker.js
file, because browsers which support ES6 syntax also support Service Workers. However, I wouldn’t recommend using the new syntax for code that registers Service Worker, unless you use a transpiler.
Related: Una Kravets’ writeup Implementing “Save For Offline” with Service Workers also forms a good start when it comes to Service Workers.