2013-10-31 132 views
1

我有我的服務器上執行此命令的緩存:瀏覽器緩存後部署

# BEGIN Expire headers 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresDefault "access plus 2 days" 
ExpiresByType image/jpeg "access plus 1 month" 
ExpiresByType image/png "access plus 1 month" 
ExpiresByType image/gif "access plus 1 month" 
ExpiresByType text/css "access plus 7 days" 
ExpiresByType text/javascript "access plus 7 days" 
ExpiresByType application/javascript "access plus 7 days" 
</IfModule> 
# END Expire headers 

我檢查和緩存工作正常。我將Capistrano設置爲部署到服務器,我的問題是部署後會發生什麼?瀏覽器會再次緩存文件,因爲它們改變了服務器上的路徑,或者用戶將不得不等待時間過期? 謝謝...

回答

1

my question is what will happen after deploy? Will the browser cache the files again because they changed the path on the server or user will have to wait for time to expire?

不幸的是用戶將不得不等待瀏覽器過期緩存數據,因爲瀏覽器有沒有辦法知道這些文件是否已經改變。但是,如果您可以更改這些文件的src paths,那麼瀏覽器將再次訪問服務器並獲取全新副本。

+0

感謝您的回答。有什麼更好的使用:eTag或LastModified強制瀏覽器再次緩存?或者你提到的 - URL指紋?再次感謝... – Wolf87

+0

'Etag'被認爲更強,檢查此鏈接:http://stackoverflow.com/questions/824152/what-takes-precedence-the-etag-or-last-modified-http-header – anubhava

+0

你歡迎,很高興它爲你解決。 – anubhava