After our conversation with Tal Ater on episode #183 about the offline revolution and his experience with Service Workers, we realized there is a lot of mystery around this new browser feature. So we've put together this essential reading list for those of you looking for the best resources out there on ServiceWorker.
Service workers essentially act as proxy servers that sit between web applications, and the browser and network. They are intended to (amongst other things) enable the creation of effective offline experiences, intercepting network requests and taking appropriate action based on whether the network is available and updated assets reside on the server. They will also allow access to push notifications and background sync APIs. - #
This was written early in the life of ServiceWorker from Matt Gaunt. Still relevant.
Rich offline experiences, periodic background syncs, push notifications— functionality that would normally require a native application—are coming to the web. Service workers provide the technical foundation that all these features will rely on.
...gain substantial performance benefits thanks to intelligent service worker caching of your UI shell for repeat visits.
I've got a function in there called stashInCache that takes a few arguments: which cache to use, the maximum number of items that should be in there, the request (URL), and the response...
You can also contribute to this growing cookbook on GitHub.
The Service Worker Cookbook is a collection of working, practical examples of using service workers in modern web apps.
David Walsh breaks down his recipe to create an app that can be used both online and offline with the help of a ServiceWorker.
The Offline Status recipe illustrates how to use a service worker to cache a known asset list and then notify the user that they may now go offline and use the app.
Dean Hume shows off code and commentary on how he uses Service Workers to intercept requests passed to the server to support additional image formats like WebP, and Internet Explorer's JPEGXR.
Service Workers open up a world of endless possibilities and this example could be extended to include other image formats and even caching. There's no reason why we can't present our users with fast web pages right now!
This is an alternate, but not the canonical, spec on ServiceWorker. It's a little easier to read through, but YMMV.
Safari has given no public commitment, while Edge is under consideration, but showing positive signals. Like any good resource, it's on GitHub.
What about a part 2 with videos?
If you know of an article or resource that needs to be listed here, let us know by opening an issue on GitHub.
We encourage our readers to suggest additions for our list-based posts. The following were suggested from our Ping repo on GitHub.
- Nicolas Bevacqua's Making a Simple Site Work Offline with ServiceWorker
- The Guardian's Building an offline page for theguardian.com