开发者

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

开发者 https://www.devze.com 2023-03-16 02:35 出处:网络
I\'m developing Javascript 开发者_C百科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.An

I'm developing Javascript 开发者_C百科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?


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.

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.


I usually press: ctrl + shift + r to clear the cache. 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. Simple and requires no change to your browser setup.


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.


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).


you can add in the .htaccess a rule for not caching a specific file or specific extension

<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

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


Try setting 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号