Help centre

Answer

What is the service worker lifecycle?

Short answer

A service worker moves through four stages: install (fired once when the browser first downloads a new or changed worker), waiting (if an old version still controls open tabs), activate (once it takes control, typically after all old tabs close or skipWaiting() is called) and idle, where the browser terminates it between events to save memory.

By InstantPWA engineering·Reviewed July 25, 2026

Install and activate

The install event is the place to precache assets. The activate event is the place to clean up old caches from a previous version.

The waiting phase

By default, a new service worker waits until every open tab controlled by the old one is closed, preventing two versions running simultaneously. self.skipWaiting() bypasses this.

Termination

Browsers kill idle service workers after roughly 30 seconds of inactivity to save resources, then wake them again on the next fetch, push or sync event.

Related
How do you update a PWA’s service worker?
Browsers automatically check your service-worker script for byte-level changes on every navigation (and roughly every 24 hours in the background). If it differs, the new version installs and waits until old tabs close before activating. Calling self.skipWaiting() in install and clients.claim() in activate makes the new version take over immediately instead of waiting.
What is a PWA?
A PWA (Progressive Web App) is a regular website that meets three technical criteria — HTTPS, a Web App Manifest and a service worker — so browsers let visitors install it on their home screen. Once installed, it launches like a native app, works offline and can send push notifications.
What is the difference between cache-first and network-first caching?
Cache-first checks the cache first and only goes to the network if there is no cached match — best for static assets like fonts and logos that rarely change. Network-first always tries the network first and falls back to the cache only if the request fails — best for content that should be as fresh as possible, like an API response, while still working offline.
What is the Background Sync API?
The Background Sync API lets a service worker register a task that the browser retries automatically once the device is back online, even if the user has closed the tab. It is commonly used so a form submission or message made while offline is not lost — it queues, then fires the moment connectivity returns.
What is Periodic Background Sync?
Periodic Background Sync lets an installed PWA periodically wake its service worker to refresh cached content — for example, prefetching news articles — even when the app is not open. It requires the periodic-background-sync permission, is only available on installed PWAs, and Chromium decides the actual interval based on site engagement, not the requested minimum.