网站提速之缓存/页面压缩篇

李洋博客 2016-03-26 1.01 W阅读 5评论

温馨提示:这篇文章已超过2943天没有更新,请注意相关的内容是否还可用!

当你使用Yslow测试网站优化评分的时候,通常会提示你:add expires headers和compress components with gzip。如果你是Apache服务器,使用htaccess进行配置无疑之最好的选择。

网站提速之缓存/页面压缩篇 第1张

以下代码在zblog php版本测试通过。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_expires.c>
# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------

# Enable expirations
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>


<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </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>

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/x-js text/js 
</IfModule>

使用后的一点点缺点... 由于缓存了...有时候需要额外刷新一下。

转载请注明:鸟儿博客 

文章版权声明:除非注明,否则均为老李笔记原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (有 5 条评论,10135人围观)
网友昵称:碧桂园十里银滩
碧桂园十里银滩 V 铁粉 Google Chrome 45.0.2454.101 Windows 10 x64 地板
2016-04-23 来自广东 回复
学习了!支持一下!
网友昵称:搬瓦工
搬瓦工 V 铁粉 Google Chrome 45.0.2454.101 Windows 7 x64 凉席
2016-03-29 来自江苏 回复
访问速度是基础,楼主分享的技巧很不错哦
网友昵称:搬瓦工
搬瓦工 V 铁粉 Google Chrome 45.0.2454.101 Windows 7 x64 板凳
2016-03-29 来自江苏 回复
网站访问速度是所有的基础啊,楼主这个技巧很好用
网友昵称:明月登楼
明月登楼 V 铁粉 Google Chrome 49.0.2623.108 Windows 10 x64 椅子
2016-03-28 来自河南 回复
学习了!支持一下!
网友昵称:boke112导航
boke112导航 V 铁粉 Google Chrome 45.0.2454.101 Windows 7 沙发
2016-03-27 来自广西 回复
博主,你好,boke112导航(博客导航站)特来拜会,发现贵站不错,已将贵站收录到博客导航的生活日记类,如有异议请留言哦!谢谢!PS:由于找不到贵站的留言板,所以就在此留言告知了,如造成困扰可删除本条评论,谢谢!
取消
微信二维码
微信二维码
支付宝二维码