service worker lifecycle
The states a service worker passes through: installing, installed and waiting, activating, activated, and finally redundant when replaced or failed.
In more detail
The install event is where you precache files; if it fails the worker becomes redundant. A new version then waits until no tabs use the old one, so a page is never controlled by two versions. The activate event is where old caches and data are cleaned up.
Related terms
- skipWaiting() — A service worker method that makes a newly installed version activate immediately instead of waiting for old tabs to close.
- clients.claim() — A service worker method that makes a newly activated worker take control of pages that are already open.
- precaching — Downloading and caching a list of essential files during a service worker's install step, so the app can load offline from the start.
- state machine — A model in which something is always in exactly one named state, such as idle, loading, success or error, and only defined events move it to another.
Taught in
- Service Worker Lifecycle: Installation, Activation And Update — Frontend Architecture & Web Platform