coderef

Service workersBaseline · Widely available

The service worker of a website is a script that runs in its own thread and which acts as local proxy that intercepts network requests from the website. Use a service worker to implement advanced caching strategies, offline support, background tasks, or push notification support on your website.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Apr 30, 2018. Widely available since Oct 30, 2020.

Browser support

DesktopChrome
1–44Not supported
45+Supportedsince Sep 1, 2015
Current: 155
Edge
12–16Not supported
17+Supportedsince Apr 30, 2018
Current: 154
Firefox
1–43Not supported
44+Supportedsince Jan 26, 2016
Current: 157
Safari
1–11Not supported
11.1+Supportedsince Apr 12, 2018
Current: 27
MobileChrome Android
18–44Not supported
45+Supportedsince Sep 1, 2015
Current: 155
Firefox Android
4–43Not supported
44+Supportedsince Jan 26, 2016
Current: 157
Safari iOS
1–11Not supported
11.3+Supportedsince Mar 29, 2018
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

JS
// main.js
if ("serviceWorker" in navigator) {
  navigator.serviceWorker.register("/sw.js");
}

// sw.js — cache-first for static assets
self.addEventListener("fetch", (event) => {
  event.respondWith(
    caches.match(event.request).then((hit) => hit ?? fetch(event.request)),
  );
});

Feature detection

JS · check before using
if ("ServiceWorker" in globalThis) {
  // ServiceWorker is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (100). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Cache40164111.1404111.3
Cache.add44164111.1444111.3
Cache.addAll46164111.1464111.3
Cache.delete43164111.1434111.3
Cache.keys43164111.1434111.3
Cache.match43164111.1434111.3
Cache.matchAll47164111.1474111.3
Cache.put43164111.1434111.3
Cache.worker_support40164411.1404411.3
CacheStorage43164111.1434111.3
CacheStorage.delete43164111.1434111.3
CacheStorage.has43164111.1434111.3
CacheStorage.keys43164111.1434111.3
CacheStorage.match54164111.1544111.3
CacheStorage.open43164111.1434111.3
CacheStorage.secure_context_required65794411.1654411.3
CacheStorage.worker_support43164411.1434411.3
Client40174411.1404411.3
Client.frameType43174411.1434411.3
Client.id40174411.1404411.3
Show 80 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Client.postMessage40174411.1404411.3
Client.type60175411.1605411.3
Client.url40174411.1404411.3
Clients40174411.1404411.3
Clients.claim42174411.1424411.3
Clients.get51174511.1514511.3
Clients.matchAll42175411.1425411.3
Clients.matchAll.options_includeUncontrolled_parameter42175411.1425411.3
Clients.openWindow40174411.1404411.3
ExtendableEvent40174411.1404411.3
ExtendableEvent.ExtendableEvent41174411.1414411.3
ExtendableEvent.waitUntil40174411.1404411.3
ExtendableEvent.waitUntil.async_waitUntil60175311.1605311.3
ExtendableMessageEvent51174411.1514411.3
ExtendableMessageEvent.ExtendableMessageEvent51174411.1514411.3
ExtendableMessageEvent.data51174411.1514411.3
ExtendableMessageEvent.lastEventId51174411.1514411.3
ExtendableMessageEvent.origin51174411.1514411.3
ExtendableMessageEvent.ports51174411.1514411.3
ExtendableMessageEvent.source51174411.1514411.3
FetchEvent40174411.1404411.3
FetchEvent.FetchEvent44174411.1444411.3
FetchEvent.clientId49174511.1494511.3
FetchEvent.handled86868416868416
FetchEvent.preloadResponse59189915.4599915.4
FetchEvent.request40174411.1404411.3
FetchEvent.respondWith42174411.1424411.3
FetchEvent.respondWith.networkerror_on_same-origin_cors667959✕6659✕
FetchEvent.respondWith.resource_url✕✕59✕✕59✕
FetchEvent.resultingClientId72796516726516
NavigationPreloadManager59189915.4599915.4
NavigationPreloadManager.disable59189915.4599915.4
NavigationPreloadManager.enable59189915.4599915.4
NavigationPreloadManager.getState59189915.4599915.4
NavigationPreloadManager.setHeaderValue59189915.4599915.4
Navigator.serviceWorker40174411.1404411.3
ServiceWorker40174411.1404411.3
ServiceWorker.postMessage40174411.1404411.3
ServiceWorker.scriptURL40174411.1404411.3
ServiceWorker.state40174411.1404411.3
ServiceWorker.statechange_event40174411.1404411.3
ServiceWorkerContainer40174411.1404411.3
ServiceWorkerContainer.controller40174411.1404411.3
ServiceWorkerContainer.controllerchange_event40174411.1404411.3
ServiceWorkerContainer.getRegistration40174411.1404411.3
ServiceWorkerContainer.getRegistrations45174411.1454411.3
ServiceWorkerContainer.message_event40174411.1404411.3
ServiceWorkerContainer.ready40174411.1404411.3
ServiceWorkerContainer.register40174411.1404411.3
ServiceWorkerContainer.startMessages74796411.1746411.3
ServiceWorkerContainer.worker_support✕✕13311.1✕13311.3
ServiceWorkerGlobalScope40174411.1404411.3
ServiceWorkerGlobalScope.activate_event40174411.1404411.3
ServiceWorkerGlobalScope.clients40174411.1404411.3
ServiceWorkerGlobalScope.fetch_event40174411.1404411.3
ServiceWorkerGlobalScope.install_event40174411.1404411.3
ServiceWorkerGlobalScope.message_event40174411.1404411.3
ServiceWorkerGlobalScope.registration42174411.1424411.3
ServiceWorkerGlobalScope.serviceWorker7979✕15.479✕15.4
ServiceWorkerGlobalScope.skipWaiting41174411.1414411.3
ServiceWorkerRegistration.active40174411.1404411.3
ServiceWorkerRegistration.installing40174411.1404411.3
ServiceWorkerRegistration.navigationPreload59179915.4599915.4
ServiceWorkerRegistration.scope40174411.1404411.3
ServiceWorkerRegistration.unregister40174411.1404411.3
ServiceWorkerRegistration.update45174411.1454411.3
ServiceWorkerRegistration.updateViaCache68185711.1685711.3
ServiceWorkerRegistration.updatefound_event40174411.1404411.3
ServiceWorkerRegistration.waiting40174411.1404411.3
WindowClient42174411.1424411.3
WindowClient.ancestorOrigins✕✕✕16✕✕16
WindowClient.focus42174411.1424411.3
WindowClient.focused42174411.1424411.3
WindowClient.navigate49175016495016
WindowClient.visibilityState42174411.1424411.3
WorkerNavigator.serviceWorker✕✕13311.1✕13311.3
caches40164111.1404111.3
caches.secure_context_required657910311.16510311.3
caches.worker_support40164111.1404111.3
http.headers.Service-Worker-Navigation-Preload5918✕15.459✕15.4