最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Disable JavaScript caching in Google Chrome - Stack Overflow

programmeradmin2浏览0评论

Is it possible to disable JavaScript caching in Google Chrome? I turned off the cache in developer tools (Ctrl-Shift-I), but it still caches JS files... Using Chrome version 20.

Is it possible to disable JavaScript caching in Google Chrome? I turned off the cache in developer tools (Ctrl-Shift-I), but it still caches JS files... Using Chrome version 20.

Share Improve this question asked Jun 14, 2012 at 8:52 KozuchKozuch 2,2923 gold badges26 silver badges38 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

For developing purposes you can use Ctrl+R or Ctrl+F5, they should not send cache headers therefore requesting the resource from server and not cache. This is called Hard Refresh.

But don't expect users to use Ctrl+R/F5, if you want to always send the uncached resource to the user, use Cache buster (Google search for cache buster)

Web browsers use the url to determine if they already know the resource, so accessing the same url will make the web browser to check if he accessed this url before thus allowing it to send a specific header of the resource it have and validate if the resource changed on the server.

Cache busters are as the name says used to bust the cache and always reload the resource. Here is an example for cache busted url:

<script type="text/javascript" src="/static/js/some.js?bust=12356"></script>

Note: it could be any name and not "bust".

A good way to always have a unique bust is using the Unix epoch time (number of seconds passed from 1.1.1970, every language offers you some function to get that number), another monly used solution is some random number. This way the browser will always get the resource from the web server.

发布评论

评论列表(0)

  1. 暂无评论