浏览器每次加载资源时,都会查看缓存内容,如果浏览器判断缓存中存在,则不重新加载资源。
可以在请求资源后面增加随机数或者时间戳,让浏览器判断此请求为新请求。
js文件加随机数方式如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<script>
document.write("<s"+"cript type='text/javascript' src='/js/test.js?"+Math.random()+"'></scr"+"ipt>");
</script>
<body>
</body>
</html>
由于Math.random()为js函数,所以需要在<script>标签中进行动态添加