2015-10-18 69 views

回答

0

您可以通過這種方式用gzip壓縮壓縮:

<ifModule mod_deflate.c> 
    <filesMatch ".(css|js|x?html?|php)$"> 
    SetOutputFilter DEFLATE 
    </filesMatch> 
</ifModule> 

要緩存文件,你可以這樣做:

<ifModule mod_headers.c> 
    <filesMatch ".(ico|jpe?g|png|gif|swf)$"> 
    Header set Cache-Control "max-age=2592000, public" 
    </filesMatch> 
    <filesMatch ".(css)$"> 
    Header set Cache-Control "max-age=604800, public" 
    </filesMatch> 
    <filesMatch ".(js)$"> 
    Header set Cache-Control "max-age=216000, private" 
    </filesMatch> 
    <filesMatch ".(x?html?|php)$"> 
    Header set Cache-Control "max-age=600, private, must-revalidate" 
    </filesMatch> 
</ifModule> 

要了解更多信息,請訪問此頁: http://samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/

+1

感謝您發佈信息。我瞭解gzip和緩存的機制。我的問題是應該以什麼順序執行?先Gzip或先緩存?我已經在堆棧溢出和其他網站上看到了這兩種方式。 –