How it works
A page registers a service worker file, which the browser installs and keeps separately from any open tab. It can intercept every network request from the site and decide whether to answer from the Cache Storage API, go to the network, or both, which is how offline pages and instant repeat visits work. It also receives push notifications and background sync events while the site is closed.
Service workers run only over HTTPS (or on localhost) and cannot touch the page's DOM. Caching strategies are easy to get wrong, and a faulty worker can keep serving stale files for a long time, so most teams use Workbox or a framework plugin. Browser extensions built on Manifest V3 also use a service worker as their background script.
Related terms
More in Rendering and architecture
App shapes