Glossary · Web Development

Service Worker

A service worker is a script that runs in the background of a browser, intercepting network requests to enable offline support, caching and push notifications.

Updated October 6, 2026

A service worker is a JavaScript file the browser runs on a separate thread from the page. It acts as a programmable proxy between the site and the network, deciding whether to answer requests from a cache or the server. It requires HTTPS.

Why it matters

Service workers power offline pages, installable web apps and fast repeat visits. They can also hide outages and cause confusion: a cached old version of the site can keep appearing after you deploy a fix, or keep working while the server is down, which makes testing misleading.

Example

self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then(hit => hit || fetch(event.request))
  );
});

This serves cached responses when available and falls back to the network.

Common mistakes

  • Caching the service worker file itself for a long time, so updates never arrive.
  • Cache-first strategies for HTML, which trap users on stale pages.
  • Not providing a way to unregister a broken worker.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.