Im trying to understand the difference between skipWaiting
and clientsClaim
. In my understanding: calling skipWaiting
will cause the new service worker to skip the waiting phase, and become active right away. clientsClaim
can then 'claim' any other open tabs as well.
What I gather from documentation online:
skipWaiting
skips the waiting phase, and becomes active right away sourceclientsClaim
immediately start controlling pages source
In every post I find online, I usually always see clientsClaim
and skipWaiting
used together.
However, I recently found a service worker that only uses clientsClaim
, and I'm having a hard time wrapping my head around what actually is the difference between clientsClaim
and skipWaiting
, and in what scenario do you use clientsClaim
but not skipWaiting
?
My thinking on this, and this may be where I'm wrong, but this is my understanding of it:
Is that calling clientsClaim
, but not skipWaiting
is redundant? Considering:
- The new service worker will become active when all open pages are closed (because we're not using
skipWaiting
) - When our new service worker is activated, we call
clientsClaim
, even though we just closed all open pages to even activate the new service worker. There should be no other pages to control, because we just closed them.
Could someone help me understand?
Read documentation on skipWaiting
Read documentation on clientsClaim
Read about service worker lifecycle by Jake Archibald, and played around with this demo
Read a bunch of stackoverflow posts, offline cookbook, different blog posts, etc.
tab-a
. If I callskipWaiting
, and refreshtab-a
, the new service worker becomes active, buttab-a
is actually still using the old service worker? (e.g.: in dev tools you'll seeservice worker #3071
as being active and running, but the previous service worker,service worker #3070
i actually still controlling the page? Additionally, what is the usecase for only usingclientsClaim
but notskipWaiting
? – Sommerville