To register a service worker, I can call
navigator.serviceWorker.register('/worker.js')
Each time a page loads it, an updated version of worker.js . If an update is found, the new worker will not be used until all tabs on the pages are closed and then reopened. The solution I read was:
self.addEventListener('install', function(event) { event.waitUntil(self.skipWaiting()); }); self.addEventListener('activate', function(event) { event.waitUntil(self.clients.claim()); });
I can understand the skipWaiting part, but what exactly does clients.claim() do? I did some simple tests and it seems to work as expected, even without it.
javascript frontend offline offline-caching service-worker
BonsaiOak
source share