2019年6月5日

3种网页缓存Js,css以及图片导致页面刷新无效果的解决办法


切图网(qietu.com)是国内专业的前端外包服务商,关于网页缓存Js,css以及图片导致页面刷新无效果的三种解决办法,如下:

方法一(php页面添加):

 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 header("Cache-Control: no-cache, must-revalidate");
 header("Pragma: no-cache");

方法二(html的head块中):

<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">

方法三:

对于图片或者css,可使用如下方式:

<img src="./data/avatar_mingpian_bak.jpg?rand=h9xqeI"  width="156" height="98">

<link rel="stylesheet" href="./style/style.css?+Math.random()">

对于js则可以直接使用时间戳:

<script language="javascript" src="UILib/Common/Common.js?time=new Date()">

微信扫一扫二维码访问