What is a service worker?
Service workers are central to PWAs. A service worker is a script that the browser runs in the background. It can act as a proxy to a web page, intercepting requests and controlling responses, and this means it can implement advanced browser features, such as offline capabilities, background syncing, and push notifications. All major browsers currently support, or are building support for, service workers.
There are a number of libraries that can be used to help with common service worker tasks, such as the sw-toolbox (github.com/GoogleChrome/sw-toolbox) and workbox (github.com/GoogleChrome/workbox) libraries. We're only going to write a simple service worker here, so we won't be using them, but they might be useful ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access