解決微信瀏覽器快取問題
微信瀏覽器處理快取方式:
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/demo.css?v=201809300011" rel="stylesheet">
<script type="text/javascript" src="js/demo.js?v=201809300011"></script>
3.跳轉另一個頁面最好封裝一個方法增加隨機數。(可以參考下邊的方法)
/** * 清理快取的方法 * 1.如果url地址有?加&, * 如果沒有加?並且增加隨機數 */ function jumpURL(url){ if (url.indexOf('?') >0) { url+="&"+Math.random(); } else { url+="?"+Math.random(); } window.location.href=url; }
歡迎大家關注“碼農新銳”。