1.meta清HTML缓存,代码如下
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
2.文件名加随机数/时间戳后缀(由PHP实现)
HTML如下
<script class="clear_cache" src="__ROOT__/js/script.js?s=<?php echo rand('10000','99999');?>"></script>
PHP如下
<?php echo rand('10000','99999');?>
3.通过JS再加随机数/时间戳,实现重载(jquery实现)
HTML如下
<script class="clear_cache" src="__ROOT__/js/script.js?s=<?php echo rand('10000','99999');?>"></script>
<link class="clear_cache" rel="stylesheet" type="text/css" href="__ROOT__/css/style.css?s=<?php echo rand('10000','99999');?>" />
jquery如下
$(document).ready(function(){
$('script.clear_cache').each(function(){
var script_url=$(this).attr('src')+Date.now();
$(this).attr('src',script_url);
});
$('link.clear_cache').each(function(){
var link_url=$(this).attr('href')+Date.now();
$(this).attr('href',link_url);
});
});