在html中,给引用的js文件自动添加版本号,去掉js缓存

在html中,给引用的js文件动态添加版本号,可以去掉js缓存,保证使用的js始终是最新的js 。

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">

	通过下面的方式,动态的为html引用的js添加版本号
	<script> 
	document.write('<script src="http://localhost:8000/aaaa.js?v='+Math.random()+'"><\/script>');
	document.write('<script src="http://localhost:8000/bbbb.js?v='+Math.random()+'"><\/script>');
	document.write('<script src="http://localhost:8000/cccc.js?v='+Math.random()+'"><\/script>');
	</script>

</head>
<body>
	<h1>给引用的js文件动态添加版本号 </h1>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/xiaojin21cen/article/details/86495767