Service Worker Vocabulary

Master Service Worker vocabulary: registration, install/activate lifecycle, fetch interception, cache strategies (cache-first, network-first), and background sync.

Vocabulary Reference

registration
The initial step: navigator.serviceWorker.register('/sw.js') tells the browser to download, parse, and begin installing the service worker script.
install event
Fired once when a new service worker version is first installed. Typically used with event.waitUntil() to pre-cache static assets before the worker takes control.
activate event
Fired after a new service worker takes control (old clients are gone). Used to clean up outdated caches from previous versions.
fetch interception
Service workers listen for the fetch event on every network request made by controlled pages. The handler can respond with a cached response, a modified request, or let the request pass through.
cache-first
Serve from the cache immediately; fall back to the network only on a cache miss. Best for versioned static assets that rarely change.
network-first
Always try the network first; serve from cache only if the network request fails. Suitable for frequently updated API responses where freshness matters.
background sync
An API that defers actions queued while offline (e.g. form submissions) and re-runs them via the service worker's sync event once connectivity is restored.