A service worker is a browser-managed worker script that can control pages after installation and activation. It intercepts requests within its scope, but cannot access the DOM. Treat it as an optional enhancement: the first visit uses the network, and the app’s core experience should still work if the worker is unavailable or not ready. section 14.8 section 14.8.1
Figure 14.1 The service worker sits between the web page and the network, including your own web server and third-party servers such as CDNs.
The diagram shows the worker between a page and network servers, including third-party servers. section 14.8
Registration and control depend on the worker’s lifecycle and scope:
- Register the worker from the page after checking browser support; its location determines which paths it can control. section 14.8.3
- During installation, perform setup such as opening a versioned cache. Activation follows when older pages no longer use the previous worker, unless that wait is deliberately shortened. section 14.8.1
An offline-capable catalog
A conservative worker precaches the app shell, data file, and JavaScript modules. Navigations try the network first, then fall back to the cached shell; an offline page is the last resort. The app still works online when service workers are unsupported. section 15.8
