2009-12-11 32 views

回答

2

它使用mod_expires

<IfModule mod_expires.c> 
    ExpiresActive On 
    ExpiresByType text/css "now plus 1 year" 
    ExpiresByType text/javascript "now plus 1 year" 
</IfModule> 
2

<FilesMatch "\.(js|css|)$">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

這應該爲你做。顯然,您可以隨時調整日期和時間。請記住,如果更新文件,您需要更改文件的名稱。

+0

謝謝您的回答。它看起來不像你可以,但是有可能產生一個從今天開始的1年期滿的期限,或者PHP是必要的嗎? – alex 2009-12-11 04:04:15

+0

您可以設置一個cron以每日更新您的.htaccess文件,但這需要您將.htaccess保持爲可寫狀態。 – Jorbin 2009-12-11 04:13:55

1

我用的是這樣的:

<IfModule mod_headers.c> 
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> 
     Header set Cache-Control "max-age=4838400, public" 
    </FilesMatch> 
    <FilesMatch "\.(css|js)$"> 
     Header set Cache-Control "max-age=4838400, private" 
    </FilesMatch> 
</IfModule> 

年齡當然秒:))

相關問題