这是程序猿经常发生的一段对话~~~
测试童鞋:“BUG根本就没有修改!”
前端童鞋:“清缓存!!清页面缓存!!你没有清缓存!!你清理了页面缓存就对了的!!😂”
这个是众多解决方法中的其中一种~
eg:
<script type=”text/javascript” src=”aa.js?version=1.2.6″></script>
<link rel=’stylesheet’ href=’bb.css?version=2.3.3′ type=’text/css’ />
code:
/**
* 给页面引用的css和js加上版本号
* @param {Object} config 配置
*/
function resource_loader(config) {
this.css = config.css;
this.scripts = config.scripts;
this.head = document.getElementsByTagName('head')[0];
//默认版本号采用时间戳,也可以自定义版本号
this.v = '?v=' + new Date().getTime();
this.load = function() {
this.loadCSS();
this.loadScript();
}
//加载css引用
this.loadCSS = function() {
var that = this;
this.css.forEach(function(csslink) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = csslink + this.v;
this.head.appendChild(link);
});
}
//加载js引用
this.loadScript = function() {
var that = this;
this.scripts.forEach(function(scriptlink) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = scriptlink + this.v;
this.head.appendChild(script);
});
}
this.load();
}
// 调用方法
resource_loader({
css: [
'content/styles/common_page.css'
],
scripts: [
'http://res.wx.qq.com/open/js/jweixin-1.4.0.js',
'content/scripts/utils/wx_config.js'
]
});
转自:http://www.cnblogs.com/zhao-yi
更多详细参考:此链接