在网站根目录下的.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 |
现在应用Firefox的YSlow插件,以Small Site or Blog尺度测试的分数为99分,以YSlow2(V2)尺度测试的分数为94分,被扣掉的几分重要是由于没有应用CDN。所以现在速度已经被优化到了极致。
赶紧把它放到你的网站或blog根目录下的.htaccess文件里吧。
原文地址:http://zhiqiang.org/blog/it/using-htaccess-to-speed-blog.html