2012-05-24 236 views
0

我有一個動態網頁,其中一小部分內容隨時都在變化。如何防止緩存網站內容?

爲每個請求由是不同的內容:Javascript和HTML

爲了使網站顯示正確的JavaScript和HTML需要從服務器100%新鮮。我檢查了不時發生的頁面錯誤是由舊/以前加載的JavaScript或HTML而不是來自服務器的新數據造成的。

我.htacces追平了以下設置:

Header Set Cache-Control "max-age=0, no-store" 

以上設置工作,但問題是,還需要每一個時間,這是聯合國必要的,是不好的網站重新加載圖像性能。

我嘗試以下設置太.htacces:

### turn on the Expires engine 
ExpiresActive On 

### expires after a month in the client's cache 
ExpiresByType image/gif A36000 
ExpiresByType image/png A36000 
ExpiresByType image/jpg A36000 
ExpiresByType image/x-icon A36000 
ExpiresByType application/pdf A36000 
### ExpiresByType application/x-javascript A36000 
### ExpiresByType text/plain A36000 

但是上面似乎並不奏效,因爲我檢查內容並不總是新鮮的,導致進入頁面錯誤。

我的問題:

我怎樣才能正確地配置服務器,從而始終(所產生的PHP腳本)新鮮HTML和JavaScript的使用?

回答

0

我用下面(PHP)的情況下,當我的應用程序具有相同的更新要求:

// disable cache (ajax useful) 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache"); 
1

什麼文字/ HTML和CSS文件不同的到期時間比圖像?

ExpiresByType text/html "access plus 5 seconds" 
ExpiresByType text/css "access plus 5 seconds" 
ExpiresByType image/jpg "access plus 5 minutes" 
etc