问题描述
我使用localhost进行开发;我直接在CDN中包含jquery。
似乎按下Ctrl + R会强制重新加载速度,包括从CDN重新下载jquery 。
我想问一下,当我刷新时,我是否保留了CDN中jquery的缓存,但清除了我的本地主机的缓存?
注意:我知道我可以做的一件事是在本地托管jquery文件;我只是要求看看是否有办法绕过这一点。
你可以防止你所有的文件碰到缓存,但这是一个全有或全无的设置。您无法决定哪些文件从缓存中清除,哪些文件保留在缓存中。在开发过程中,由于您使用的是Chrome,因此我建议启用Disable cache(DevTools is open)的设置:
如果你和我一样,每当你打开DevTools面板时,缓存将被禁用。
>您可以做的另一件事是指示您的服务器绕过所有资源的缓存。由于jQuery来自CDN,因此这个无缓存设置将不适用于它。要禁用资源缓存,您可以包含以下响应头:
缓存控制:no-cache,no-store
I'm using localhost for development; and I'm directly including jquery from CDN.
It seems that pressing the "Ctrl + R" would force the pace to reload, including re-downloading the jquery from CDN.
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?
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.
During development, since you are using Chrome, I'd recommend to enable the setting for "Disable cache (while DevTools is open)":
If you are like me, cache will be disabled every time you have the DevTools panel opened.
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 - 只为本地主机禁用缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!