Chrome - 仅禁用本地主机的缓存? [英] Chrome - Disable cache for localhost only?

查看:43
本文介绍了Chrome - 仅禁用本地主机的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 localhost 进行开发;我直接从 CDN 包含 jquery.

I'm using localhost for development; and I'm directly including jquery from CDN.

似乎按下Ctrl + R"会强制页面重新加载,包括从 CDN 重新下载 jquery.

It seems that pressing the "Ctrl + R" would force the page to reload, including re-downloading the jquery from CDN.

我想问一下是否有可能..刷新时,我保留了来自 CDN 的 jquery 缓存,但清除了我的 localhost 缓存?

I want to ask if it's possible that.. when I refresh, I keep the cache of the jquery from CDN, but clear the cache of my localhost?

注意:我知道我可以做的一件事是在本地托管 jquery 文件;我只是想看看是否有办法绕过它.

NOTE: I know that one thing I can do is to host jquery file locally; I'm just asking to see if there's a way to bypass that.

推荐答案

您当然可以防止所有文件访问缓存,但这是一个全有或全无的设置.您无法决定哪些文件从缓存中清除,哪些文件保留在缓存中.

You can certainly prevent all your file from hitting the cache, but this is an all-or-nothing setting. You can't decide which files get cleared from the cache and which files stay in the cache.

在开发过程中,由于您使用的是 Chrome,我建议您启用禁用缓存(DevTools 打开时)"的设置:

During development, since you are using Chrome, I'd recommend to enable the setting for "Disable cache (while DevTools is open)":

如果你像我一样,每次打开 DevTools 面板都会禁用缓存.

If you are like me, cache will be disabled every time you have the DevTools panel opened.

您可以做的另一件事是指示您的服务器完全绕过所有资源的缓存.由于 jQuery 来自 CDN,因此此无缓存设置不适用于它.要禁用资源缓存,您可以包含以下响应标头:

Another thing you can do is to instruct your server to bypass cache altogether for all your resources. Since jQuery is coming from a CDN, this no-cache setting won't apply for it. To disable cache for resources you can include the following response header:

Cache-Control:no-cache, no-store

这篇关于Chrome - 仅禁用本地主机的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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