在網(wǎng)站根目錄下的.htaccess文件中添加以下代碼
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/gif A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/png A2592000 ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType text/css A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType application/javascript A2592000 ExpiresByType text/javascript A2592000 ExpiresByType text/html A600 </IfModule> <IfModule mod_deflate.c> <FilesMatch "\.(js|css|html|htm)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule> <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule> <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css)$"> Header unset Last-Modified </FilesMatch> FileETag none |
現(xiàn)在應(yīng)用Firefox的YSlow插件,以Small Site or Blog尺度測試的分數(shù)為99分,以YSlow2(V2)尺度測試的分數(shù)為94分,被扣掉的幾分重要是由于沒有應(yīng)用CDN。所以現(xiàn)在速度已經(jīng)被優(yōu)化到了極致。
趕緊把它放到你的網(wǎng)站或blog根目錄下的.htaccess文件里吧。
原文地址:http://zhiqiang.org/blog/it/using-htaccess-to-speed-blog.html