解决微信浏览器缓存问题,主要针对h5

2019-06-25  本文已影响0人  幻听86

微信浏览器处理缓存方式:

1.头部处理缓存信息。

                 <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.修改js或css文件时加上版本号信息。

                   <link href="css/app.css?v=20190625" rel="stylesheet">

                   <script type="text/javascript" src="js/app.js?v=20190625"></script>

3.跳转另一个页面最好封装一个方法增加随机数。(可以参考下边的方法)

/**

 *  清理缓存的方法

 * 1.如果url地址有?加&,如果没有加?并且增加随机数 

 */

function toNewPage(url){

     if (url.indexOf('?') >0) {

          url+="&"+Math.random();

     } else {

          url+="?"+Math.random();

     }

    window.location.href=url;

}

上一篇 下一篇

猜你喜欢

热点阅读