Service Worker
A background script the browser runs between a page and the network, able to intercept requests even when no page is open.
Service Worker is a script the browser installs and runs separately from any page, sitting as a programmable proxy between the page and the network. It can intercept every fetch a page makes, answer from a cache instead of the network, or synthesize a response outright — and, distinctively, it keeps running (briefly) after the page that registered it closes, which is what lets it handle background sync and push notifications with no tab open at all.
The thing that makes it powerful and awkward in equal measure is its lifecycle: a service worker installs, then waits to activate until every open tab using the old version has closed, so a page can be running against a stale worker for a surprisingly long time unless the app explicitly calls skipWaiting(). Debugging "why isn't my update showing up" in a service-worker-backed app is, overwhelmingly, this lifecycle rather than a caching bug.
Its main application is offline support and precise cache control: a service worker can implement cache-first, network-first, or stale-while-revalidate strategies per request, giving an app control over caching behavior far more fine-grained than HTTP Caching headers alone provide. This is the mechanism underneath most installable web apps and PWAs — the app shell loads from the service worker's cache instantly, with the network only fetching what's actually changed.
It's a cousin of Web Worker, sharing the same off-main-thread execution model and inability to touch the Document Object Model directly, but a Web Worker exists to run computation for one page and dies with it; a service worker exists to intercept network traffic and outlives the page entirely, scoped to an origin rather than a tab.
See also4
Web Worker
A background thread for running JavaScript off the main thread, with no access to the DOM.
Web Platform12 connections
HTTP Caching
The set of headers that let a browser or intermediary reuse a previous response instead of re-fetching it.
Web Platform18 connections
ETag
An opaque fingerprint of a response's content that lets a client ask a server whether it's changed without re-downloading it.
Web Platform7 connections
Progressive Enhancement
Building so the core experience works without scripts, with richer behavior layered on top.
Web Platform26 connections
Related3
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from8
- Background Tab ThrottlingWeb Platform
Browsers deliberately slow, freeze, or discard pages that are not visible, so code that assumes it keeps running in the background will be wrong.
- Browser ExtensionWeb Platform
Small programs that modify the browser and the pages it shows, from bookmarklets and userscripts to ad blockers, with access broad enough to make them a standing security risk.
- Cross-Tab CommunicationWeb Platform
Keeping several open tabs of the same app consistent, best done by broadcasting small notifications and letting each tab re-read the truth.
- HTTP CachingWeb Platform
The set of headers that let a browser or intermediary reuse a previous response instead of re-fetching it.
- MIME TypeWeb Platform
The short type/subtype label, born in email, that tells a browser how to treat a response, and why browsers that guess when it's missing turned a convenience into a security hole.
- Progressive Web AppWeb Platform
A website that can be installed like a native app, launched from the home screen in its own window and used offline, built from a manifest, a service worker and HTTPS.
- Web StorageWeb Platform
The browser's built-in ways to keep data on the user's device, from the simple string store localStorage to the transactional database IndexedDB, and their limits on size, persistence and security.
- Web WorkerWeb Platform
A background thread for running JavaScript off the main thread, with no access to the DOM.