Updating and Activating Service Workers
Learn how to successfully update an existing service worker with a new one.
We'll cover the following
As developers, we need to make code changes. Similarly, there can be a need to update the service worker of a live application. Let’s assume that we’ve made changes in a service worker. The following will happen when we run our app (over an HTTPS or a localhost server).
- The browser will check if the service worker has changed and perform the following actions:
- If it finds that the code inside the service worker is updated, it will register and install this service worker.
- Otherwise, it will simply ignore the service worker registration code.
- If the browser installs a new service worker, it must make certain decisions before activating this new service worker. For example, the browser will check if any open tab is using the old service worker and perform the following actions:
- If it finds such a tab, it will put the new service worker in the
waiting
phase. The browser will activate the new service worker only after all the instances of the old service worker have been closed. - Otherwise, it will activate the new service worker immediately.
- If it finds such a tab, it will put the new service worker in the
Get hands-on with 1200+ tech skills courses.