在Chrome浏览器中停用JavaScript缓存 [英] Disable JavaScript caching in Google Chrome

查看:117
本文介绍了在Chrome浏览器中停用JavaScript缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Google Chrome中停用JavaScript缓存?我关闭了开发人员工具中的缓存(Ctrl-Shift-I),但它仍然缓存JS文件...使用Chrome 20版本。 为了开发目的,您可以使用Ctrl + R或Ctrl + F5,它们不应该发送缓存标头,因此请求服务器的资源而不缓存。这就是所谓的硬刷新。



但是不要指望用户使用Ctrl + R / F5,如果你想总是将未缓存的资源发送给用户, a href =http://www.adopsinsider.com/ad-ops-basics/what-is-a-cache-buster-and-how-does-it-work/ =noreferrer>缓存拦截器( Google搜索缓存拦截器



Web浏览器使用url来确定他们是否已经知道资源,因此访问相同的url将使Web浏览器检查他是否访问了此URL,因此允许它发送特定的页眉它具有的资源并验证服务器上的资源是否已更改。



高速缓冲存储器总线正如名称所示,用于缓存高速缓存并始终重新加载资源。
这里是一个缓存破坏URL的例子:

 < script type =text / javascriptsrc = /static/js/some.js?bust=12356\"></script> 

注意:它可以是任何名称而不是胸围。



总是有一个独特的萧条的好方法是使用Unix纪元时间(秒数从2001年1月1日开始传递,每种语言都提供了一些函数来获取该数字),另一个常用的解决方案是随机数。这样浏览器将始终从Web服务器获取资源。


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.

解决方案

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 commonly used solution is some random number. This way the browser will always get the resource from the web server.

这篇关于在Chrome浏览器中停用JavaScript缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆