简体   繁体   English

如何在 Chrome 中为特定网站关闭缓存?

[英]How can I turn caching off in Chrome for a particular website?

I'm developing Javascript for a website called www.example.com and Chrome keeps caching earlier versions of my code.我正在为一个名为 www.example.com 的网站开发 Javascript,Chrome 一直在缓存我的代码的早期版本。 I can continuously clear the cache, but that's becoming a time sink.我可以不断地清除缓存,但这正在成为一个时间槽。 Any other options?还有其他选择吗?

If you do not want to change the code for your webpage.如果您不想更改网页的代码。 You can simply open developer tools on Google Chrome.您只需在 Google Chrome 上打开开发者工具即可。 Shortcut: Ctrl+Shift+i on windows.快捷方式:在 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.选中“禁用缓存”,你对 go 很好。

I usually press: ctrl + shift + r to clear the cache.我通常按:ctrl + shift + r 来清除缓存。 That I find the easiest.我觉得最简单的。

This also works:这也有效:

<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">

If you use an incognito window for debugging- it has no cached data.如果您使用隐身 window 进行调试 - 它没有缓存数据。 Simple and requires no change to your browser setup.简单,无需更改浏览器设置。

I do this myself for development.我自己这样做是为了发展。 I use CTRL-F5.我使用 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.这会刷新页面,包括重新下载任何引用的 JS 文件或 CSS 文件,即使它们已被缓存。

Add these headers to your web pages during development:在开发过程中将这些标头添加到您的 web 页面:

<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 标头(在开发期间)。

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或用于 all.js 和 css

<FilesMatch "\.(js|css)$"> 

Try setting HTTP header:尝试设置 HTTP header:

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.但这应该只在开发过程中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM