Service Worker
A service worker is a JavaScript script that runs in the background of a web browser, separate from the main web page, enabling features like offline access, push notifications, and background sync.
Service workers act as a programmable proxy between your web application and the network. They intercept network requests and can serve cached responses, enable offline functionality, handle push notifications, and perform background data synchronization, all without requiring the web page to be open. The most impactful use of service workers is caching strategies.
Different caching strategies apply to different content: cache-first for static assets (serve from cache, update in background), network-first for dynamic content (try network, fall back to cache), and stale-while-revalidate for a balance of speed and freshness. Service workers are the foundation of Progressive Web Apps (PWAs).
In practice
- A news app implemented service workers for offline reading, users can download articles on Wi-Fi and read them during their subway commute
- A retail PWA caches the product catalog, so returning customers see products instantly instead of waiting for network requests
- A field service application uses service workers to let technicians fill out forms offline, syncing the data when they regain connectivity
- A documentation site caches all pages on first visit, making subsequent page navigations appear instant and the entire site available offline
Not sure how this applies to you?
A senior engineer walks your site, your search presence and the way enquiries reach you, then writes down the three things worth fixing first. You keep the document either way.
