javascript 如何在 Chrome 中为特定网站关闭缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6527215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I turn caching off in Chrome for a particular website?
提问by JnBrymn
I'm developing Javascript for a website called www.example.com and Chrome keeps caching earlier versions of my code. I can continuously clear the cache, but that's becoming a time sink. Any other options?
我正在为一个名为 www.example.com 的网站开发 Javascript,而 Chrome 一直缓存我的代码的早期版本。我可以不断清除缓存,但这正在成为一个时间槽。还有其他选择吗?
回答by user740857
If you do not want to change the code for your webpage. You can simply open developer tools on Google Chrome. Shortcut: Ctrl+Shift+i on windows.
如果您不想更改网页的代码。您只需在 Google Chrome 上打开开发人员工具即可。快捷键:Windows 上的 Ctrl+Shift+i。
You'll find a gear on the bottom-right corner that'll take you to settings. Check "disable cache" and you're good to go.
您会在右下角找到一个可以带您进入设置的齿轮。选中“禁用缓存”就可以了。
回答by Nish
I usually press: ctrl + shift + r to clear the cache. That I find the easiest.
我通常按:ctrl + shift + r 清除缓存。我觉得最简单的。
This also works:
这也有效:
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
回答by Rob
If you use an incognito window for debugging- it has no cached data. Simple and requires no change to your browser setup.
如果您使用隐身窗口进行调试 - 它没有缓存数据。简单,无需更改浏览器设置。
回答by Durgaprasad Budhwani
I do this myself for development. I use CTRL-F5. Its like a force refresh. This refreshes the page including re-downloading any referenced JS files or CSS files even if they were cached.
我自己做这个是为了开发。我使用 CTRL-F5。它就像强制刷新。这会刷新页面,包括重新下载任何引用的 JS 文件或 CSS 文件,即使它们已被缓存。
回答by jfriend00
Add these headers to your web pages during development:
在开发过程中将这些标题添加到您的网页中:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
Or you can configure your web server to put no-cache info in the http headers (during development).
或者您可以配置您的 Web 服务器以在 http 标头中放置无缓存信息(在开发期间)。
回答by Tarek
you can add in the .htaccess a rule for not caching a specific file or specific extension
您可以在 .htaccess 中添加不缓存特定文件或特定扩展名的规则
<FilesMatch "script.js$">
Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma
</FilesMatch>
or for all .js & css
或所有 .js 和 css
<FilesMatch "\.(js|css)$">
回答by Nick B
Try setting HTTP header:
尝试设置 HTTP 标头:
Cache-Control: no-cache, no-store
Or:
或者:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE, NO-STORE">
But this should only be used during development.
但这应该只在开发过程中使用。