Reputation: 4729
The image below shows that there are two workers installed - one active and the other not active (just installed).
service-worker.js
and reload the page.So a new service worker is spawned with a new version ID. But why does the old one keeps running ? and How do I close it ?
The sw.js
is here https://gist.github.com/boopathi/57b7e8b6d657d55bdc7d
Upvotes: 7
Views: 3594
Reputation: 56074
By default, until all tabs that have a page controlled by that old service worker are closed/unloaded, the old service worker will stay running. The new service worker will, well, "wait" in the "waiting" state.
There are options that change this default behavior. They're skipWaiting()
and clients.claim()
.
When skipWaiting()
is called from an installing service worker, it will, well, skip the "waiting" state and immediately activate. However, it will not necessarily take control of pages despite being activated—that's what clients.claim()
will accomplish.
Upvotes: 12