The cache
read-only property of the Request
interface contains the cache mode of the request. It controls how the request will interact with the browser's HTTP cache.
var currentCacheMode = request.cache;
A RequestCache
value. The available values are:
default
— The browser looks for a matching request in its HTTP cache. no-store
— The browser fetches the resource from the remote server without first looking in the cache, and will not update the cache with the downloaded resource.reload
— The browser fetches the resource from the remote server without first looking in the cache, but then will update the cache with the downloaded resource.no-cache
— The browser looks for a matching request in its HTTP cache. force-cache
— The browser looks for a matching request in its HTTP cache. only-if-cached
— The browser looks for a matching request in its HTTP cache. "only-if-cached"
mode can only be used if the request's mode
is "same-origin"
. Cached redirects will be followed if the request's redirect
property is "follow"
and the redirects do not violate the "same-origin"
mode.// Download a resource with cache busting, to bypass the cache // completely. fetch("some.json", {cache: "no-store"}) .then(function(response) { /* consume the response */ }); // Download a resource with cache busting, but update the HTTP // cache with the downloaded resource. fetch("some.json", {cache: "reload"}) .then(function(response) { /* consume the response */ }); // Download a resource with cache busting when dealing with a // properly configured server that will send the correct ETag // and Date headers and properly handle If-Modified-Since and // If-None-Match request headers, therefore we can rely on the // validation to guarantee a fresh response. fetch("some.json", {cache: "no-cache"}) .then(function(response) { /* consume the response */ }); // Download a resource with economics in mind! Prefer a cached // albeit stale response to conserve as much bandwidth as possible. fetch("some.json", {cache: "force-cache"}) .then(function(response) { /* consume the response */ });
Specification | Status | Comment |
---|---|---|
Fetch The definition of 'cache' in that specification. | Living Standard | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | Nightly build | (Yes) | 48 (48) | No support | No support | 11 |
only-if-cached | No support | ? | 50 (50) | No support | No support | No support |
Feature | Android | Edge | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | No support | (Yes) | No support | No support | No support | No support | No support | No support |
only-if-cached | No support | ? | No support | No support | No support | No support | No support | No support |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Request/cache