1.meta方法
HTML header中加入
<meta http-equiv="pragma" content="no-cache">
說明:禁止瀏覽器從本地計算機的緩存中訪問頁面內容。上述設定,訪問者將無法脫機瀏覽。
<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
說明:Cache-Control指定請求和響應遵循的緩存機制,no-cache指示請求或響應消息不能緩存,must-revalidate,對於客戶機的每次請求,代理服務器必須想服務器驗證緩存是 否過時;
<meta http-equiv="expires" content="0">
說明:可以用於設定網頁的到期時間。一旦網頁過期,必須到服務器上重新傳輸。
合起來用,就可以使你再次進入曾經訪問過的頁面時,瀏覽器必須從服務端下載最新的內容,達到刷新的效果。
2.清理form表單的臨時緩存
document.getElementById("YourFormID").reset();
說明:js重置表單(reset)的方法。
在form中加入autocomplete='off'屬性,或者在input中加入autocomplete='off'屬性
說明:關閉自動填充。
3.jquery--ajax清除緩存
A.用ajax請求服務器最新文件,並加上請求頭If-Modified-Since和Cache-Control,如下:
$.ajax({ url:'', dataType:'json', beforeSend :function(xmlHttp){ xmlHttp.setRequestHeader("If-Modified-Since","0"); xmlHttp.setRequestHeader("Cache-Control","no-cache"); }, success:function(response){ } });
B.直接用cache:false
$.ajax({ url:', dataType:'json', cache:false, success:function(response){ } });
C.用隨機數或者隨機時間避免緩存
$.ajax({
//隨機數 url:'YourURL?ran='+Math.random(), dataType:'json', success:function(response){ } });
$.ajax({
//隨機時間 url:'YourURL?timestamp='+ new Date().getTime(), dataType:'json', success:function(response){ } });