This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The match() method of the CacheStorage interface checks if a given Request or URL string is a key for a stored Response. This method returns a Promise for a Response, or a Promise which resolves to undefined if no match is found.
You can access CacheStorage through the Window.caches property in windows or through the WorkerGlobalScope.caches property in workers.
Cache objects are searched in creation order.
Note: caches.match() is a convenience method. Equivalent functionality is to call cache.match() on each cache (in the order returned by caches.keys()) until a Response is returned.
match(request) match(request, options)
requestThe Request you want to match. This can be a Request object or a URL string.
options OptionalAn object whose properties control how matching is done in the match operation. The available options are:
ignoreSearchA boolean value that specifies whether the matching process should ignore the query string in the URL. For example, if set to true, the ?value=bar part of http://foo.com/?value=bar would be ignored when performing a match. It defaults to false.
ignoreMethodA boolean value that, when set to true, prevents matching operations from validating the Request http method (normally only GET and HEAD are allowed.) It defaults to false.
ignoreVaryA boolean value that, when set to true, tells the matching operation not to perform VARY header matching. In other words, if the URL matches you will get a match regardless of whether the Response object has a VARY header or not. It defaults to false.
cacheNameA string that represents a specific cache to search within.
a Promise that resolves to the matching Response. If no matching response to the specified request is found, the promise resolves with undefined.
This example is from the MDN simple service worker example (see simple service worker running live). Here we wait for a FetchEvent to fire. We construct a custom response like so:
CacheStorage using CacheStorage.match(). If so, serve that.v1 cache using open(), put the default network request in the cache using Cache.put() and return a clone of the default network request using return response.clone(). The last is necessary because put() consumes the response body.self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
// caches.match() always resolves
// but in case of success response will have value
if (response !== undefined) {
return response;
}
return fetch(event.request)
.then((response) => {
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
let responseClone = response.clone();
caches
.open("v1")
.then((cache) => cache.put(event.request, responseClone));
return response;
})
.catch(() => caches.match("/gallery/myLittleVader.jpg"));
}),
);
});
| Specification |
|---|
| Service Workers> # cache-storage-match> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
match |
5440–54The options parameter only supportsignoreSearch, and cacheName. |
16 | 41 | 4127–41The options parameter only supportsignoreSearch, and cacheName. |
11.1 | 5440–54The options parameter only supportsignoreSearch, and cacheName. |
41 | 4127–41The options parameter only supportsignoreSearch, and cacheName. |
11.3 | 6.04.0–6.0The options parameter only supportsignoreSearch, and cacheName. |
5440–54The options parameter only supportsignoreSearch, and cacheName. |
11.3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage/match