Disable cache for certain resource programmatically

痴心易碎 提交于 2021-02-08 10:14:58

问题


I have this setting in Chrome devtools:

this setting works for me. However, I also want to disable the cache for certain resources. My question is - is there a way to disable the cache for a resource when you use fetch?

fetch(url).then(v => {});

is there some option or header that we can use to prevent the browser from using the cache to retrieve the resource?


回答1:


This has the answers I was looking for:

https://hacks.mozilla.org/2016/03/referrer-and-cache-control-apis-for-fetch/

first make sure caching is disabled on the server, if necessary.

Then in the browser, we can use one of these:

fetch(url, {cache: 'no-store'})

or

fetch(url, {cache: 'no-cache'})

and get the result we want to achieve.



来源:https://stackoverflow.com/questions/48836369/disable-cache-for-certain-resource-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!