js文件和css文件的禁止其缓存
- 有的时候在调试页面的时候,刷新浏览器没用,
重新点地址栏也不行,只能去浏览器设置里清除缓存,讨厌的要死,
有时候还不得不把常用的cookie删掉,所以打算在开发或者已经上线后,
希望用户每次都重新请求,保证版本的最新
方法一
- 普通青年
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-control" content="no-cache"/>
<meta http-equiv="Cache" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
- 文艺青年
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="content-type" content="no-cache, must-revalidate" />
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
- 大部分时间发现上边方法没用,尝试一下下边这个方法。
<body onLoad="javascript:document.yourFormName.reset()">
- 上边这个方法只能更改第一次引入的情况,
也就是在你html页面原本就有的,只要一刷新,就进来了,
问题来了,动态引进来的就不好使了,还是会缓存的
- 那就要在引入的时候加这个文件的后边加上问好,然后跟上随机数或者时间戳就好了
var now=new Date();
var str='<script src="js/commenTools.js?time='+now.getTime()+'" type="text/javascript"></scr'+'ipt>';
document.write(str);
###不要写成这个样子
// var str='<script src="js/commenTools.js'+now.getTime()+'" type="text/javascript"></script>'
跟上边啥区别,慢慢找。只有吃过亏才知道咋回事。

浙公网安备 33010602011771号