使用 fetch('somefile.json')
,可以请求从服务器而不是浏览器缓存中获取文件吗?
换句话说,使用fetch()
,是否可以绕过浏览器的缓存?
最佳答案
更容易使用缓存模式:
// 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 */ });
引用:https://hacks.mozilla.org/2016/03/referrer-and-cache-control-apis-for-fetch/
关于javascript - fetch(),你如何发出非缓存请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29246444/