Definition
fetch event (service worker)
The fetch event fires in the service worker for every navigation, script, image or XHR request originating from a page it controls. Calling event.respondWith(promise) lets the worker substitute its own Response, most commonly by checking the Cache Storage API first and falling back to fetch() from the network.
A cache-first example: self.addEventListener("fetch", (event) => { event.respondWith(caches.match(event.request).then((cached) => cached || fetch(event.request))); });, one of the simplest strategies and a reasonable default for versioned static assets.
If a fetch handler does not call event.respondWith(), the request proceeds to the network exactly as if no service worker were present — this is why registering a worker with no fetch listener has zero effect on network behaviour, only on lifecycle and push events.
The fetch event does not fire for cross-origin requests unless the request is same-origin or the response is opaque and explicitly requested with mode: "no-cors", and it never fires for requests from a page the worker does not yet control (the first load after registration is typically served straight from the network).
Choosing the right strategy per request type — cache-first for immutable hashed assets, network-first for API calls, stale-while-revalidate for things like avatars — is the core design decision of any service worker; see web.dev's offline cookbook: https://web.dev/articles/offline-cookbook.