Service Workers: Overview
What is a service worker?
Section titled “What is a service worker?”A service worker is a JavaScript file that runs in the background — separate from your web page — in its own worker thread. Because it lives outside the page, it has no access to the DOM, document, or window. What it does have is the power to intercept and respond to every network request your page makes.
Think of a service worker as a programmable network proxy sitting between your page and the internet. You decide what happens to each request: pass it straight to the network, serve it from a local cache, or construct a response entirely from scratch.
This capability is the foundation of every offline-first PWA feature you will build in this course:
| Capability | How the service worker enables it |
|---|---|
| Offline support | Intercepts requests and serves from cache |
| Push notifications | Receives push events even while the page is closed |
| Background sync | Queues failed requests and retries when online |
| Instant load | Serves pre-cached assets without a network round-trip |
flowchart LR
P["Page / App"] -->|"fetch()"| SW["Service Worker"]
SW -->|"cache hit"| C[("Cache Storage")]
SW -->|"cache miss"| N["Network"]
N -->|response| SW
C -->|response| SW
SW -->|response| P What this module covers
Section titled “What this module covers”This module takes you from zero to confident with service workers in five lessons:
- Overview (this page) — what a service worker is and how it interacts with the page.
- Registering a service worker — how the page loads and activates a service worker.
- Lifecycle — the install → waiting → activate → active state machine every SW goes through.
- The fetch event — intercepting requests and deciding how to respond.
- Updating service workers — how browsers detect changes and how to push updates safely.
Each lesson is standalone: come back to any of them at any time.