This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
This is the event type for fetch events dispatched on the service worker global scope. It contains information about the fetch, including the request and how the receiver will treat the response. It provides the event.respondWith() method, which allows us to provide a response to this fetch.
Constructor
FetchEvent()- Creates a new
FetchEventobject. This constructor is not typically used. The browser creates these objects itself and provides them tofetchevent callbacks.
Properties
Inherits properties from its ancestor, Event.
fetchEvent.clientIdRead only- The
idof the same-originclientthat initiated the fetch. fetchEvent.preloadResponseRead only- A
Promisefor aResponse, or void if this is not a navigation, or navigation preload is not enabled. fetchEvent.requestRead only- The
Requestthe browser intends to make.
Methods
Inherits methods from its parent, ExtendableEvent.
fetchEvent.respondWith()- Prevent the browser's default fetch handling, and provide (a promise for) a response yourself.
extendableEvent.waitUntil()-
Extends the lifetime of the event. Used to notify the browser of tasks that extend beyond the returning of a response, such as streaming and caching.
Examples
This fetch event uses the browser default for non-GET requests. For GET requests it tries to return a match in the cache, and falls back to the network. If it finds a match in the cache, it asynchronously updates the cache for next time.
addEventListener('fetch', event => {
// Let the browser do its default thing
// for non-GET requests.
if (event.request.method != 'GET') return;
// Prevent the default, and handle the request ourselves.
event.respondWith(async function() {
// Try to get the response from a cache.
const cache = await caches.open('dynamic-v1');
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
// If we found a match in the cache, return it, but also
// update the entry in the cache in the background.
event.waitUntil(cache.add(event.request));
return cachedResponse;
}
// If we didn't find a match in the cache, use the network.
return fetch(event.request);
}());
});
Specifications
| Specification | Status | Comment |
|---|---|---|
| Service Workers The definition of 'FetchEvent' in that specification. |
Editor's Draft | Initial definition. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 40 | 44.0 (44.0)[1] | No support | 27 | No support |
preloadResponse property |
59 | ? | ? | 46 | ? |
| Feature | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | 40 | 40 | 44.0 (44.0) | (Yes) | No support | 27 | No support |
preloadResponse property |
59 | 59 | ? | ? | ? | 46 | ? |
[1] Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR.)

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
