Is it possible to track geolocation with a service worker while PWA is not open

The solution is at hand and has been for some years now as this POC clearly testifies. Unfortunately W3C have fought tooth and nail to prevent it from being made available 🙁 Why? I know not. The “cui bono” argument points to plug-in vendors such as Ionic whose whole raison d’etre appears to be background … Read more

Can I have multiple service workers both intercept the same fetch request?

No, you can not. Only one service worker per scope is allowed to be registered so the latest kick the previous one out unless the scope is more specific, in this case, the request is attended by the most specific only. Nevertheless, you can attach multiple fetch handlers and they all will process the request … Read more

When does code in a service worker outside of an event handler run?

In general, code that’s outside any event handler, in the “top-level” of the service worker’s global scope, will run each and every time the service worker thread(/process) is started up. The service worker thread may start (and stop) at arbitrary times, and it’s not tied to the lifetime of the web pages it controlled. (Starting/stopping … Read more

What’s the difference between using the Service Worker Cache API and regular browser cache?

The primary difference is control. Browser cache is driven off Cache-Control headers, which is good, until its not. There are all sorts of strategies to manage how network addressable resources are cached; private, public; time to live, etc. With service worker caching you can programmatically control how those assets are persisted. But that means the … Read more

navigator.serviceWorker is never ready

The problem was that the service-worker.js file was stored in an assets sub-directory. Don’t do that: store the service-worker.js in the root of your app (or higher). That way your app can access the service-worker. See HTML5Rocks article — One subtlety with the register method is the location of the service worker file. You’ll notice … Read more