以编程方式禁用某些资源的缓存 [英] Disable cache for certain resource programmatically

查看:84
本文介绍了以编程方式禁用某些资源的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome devtools中具有此设置:

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?

推荐答案

这是我一直在寻找的答案:

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'})

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

并获得我们想要实现的结果.

and get the result we want to achieve.

这篇关于以编程方式禁用某些资源的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆