What a service worker is
A service worker is a script that a web browser runs in the background, completely separate from the web page a person is viewing. It acts as a programmable proxy sitting between a web app and the network, able to intercept requests and decide how to respond. Because it runs apart from the page, it keeps working even when the page is closed, which is what makes features like offline access and push notifications possible on the web.
Intercepting network requests
The core ability of a service worker is to catch every network request a web app makes and choose what to do with it. It can pass the request through to the network, answer it from a local cache, or combine the two. This control is why a well-built web app can keep showing content when the connection drops, because the service worker serves saved files instead of failing with an error.
The lifecycle
A service worker goes through a clear lifecycle. First it is registered by the page, then installed, which is a good moment to cache essential files. After installation it becomes active and starts controlling pages the next time they load. Browsers deliberately keep a new service worker from taking over immediately, so an existing version stays in charge until all of its pages are closed, which prevents two versions from clashing.
Caching and offline support
Service workers rely on the Cache API, a separate storage area for request and response pairs. A common pattern caches the app's core files during installation and serves them instantly on later visits, a technique that makes the app load fast and work offline. Developers choose strategies such as cache-first for unchanging assets or network-first for fresh data, balancing speed against how current the content needs to be.
Security and limits
Because a service worker can intercept all of a site's traffic, browsers require it to be served over HTTPS, so an attacker cannot inject one over an insecure connection. It also cannot touch the page's content directly, since it has no access to the document; instead it communicates with pages through messages. These limits keep a powerful feature from becoming a security risk, while still allowing rich offline behavior.
The bottom line
A service worker is a background script that lets a website intercept network requests, cache files, work offline, and receive push notifications. It is the technology that makes progressive web apps feel like installed software. Understanding its lifecycle and caching role explains how modern sites load instantly on repeat visits and keep working even when the network does not.
Related on Skillo
See also: What is caching? Explained, What is an API? Explained simply.
Sources
Published date reflects the original event date (2026-10-23). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Leave a Reply