DEV Community

Discussion on: #04 - Make Progressive Web Apps Reliable

Collapse
 
jeffposnick profile image
Jeff Posnick • Edited

This is great, Nitya! One correction to add:

If there is an old service worker in play, you can use clients.claim() to immediately replace the old service worker with your new one.

clients.claim() does not affect whether an old service worker is immediately replaced by a new one. (If there is both an old and a newly updated service worker with the same scope, the new one will remain in a "waiting" state indefinitely until either a) all the clients of the old service worker have closed or b) the new service worker calls self.skipWaiting().)

clients.claim() is useful during the very first time a service worker is registered for a given scope, if you want it to take control of pages that are already open after it finishes installation. If you don't call it, the newly registered service worker won't be in control of anything already open, and it will only start controlling pages after the next navigation to an in-scope URL.

There's more info in Jake's fantastic "The Service Worker Lifecycle".

Collapse
 
nitya profile image
Nitya Narasimhan, Ph.D

Thanks Jeff!! Will take this change back to the main docs and update along with other feedback, to provide clarifications.