本文作者:DurkBlue

如何用页面压缩来为网站提速呢推荐

DurkBlue 2020-03-02 1763 3条评论
如何用页面压缩来为网站提速呢摘要: 当你使用Yslow测试网站优化评分的时候,通常会提示你:add expires headers和compress components with gzip。如果你是Apache服务...

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

如何用页面压缩来为网站提速呢  第1张

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

如何用页面压缩来为网站提速呢  第2张 Markup
<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>

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

此篇文章由DurkBlue发布,转载一下需要注明来处
文章投稿或转载声明

来源:DurkBlue版权归原作者所有,转载请保留出处。本站文章发布于 2020-03-02
温馨提示:文章内容系作者个人观点,不代表DurkBlue博客对其观点赞同或支持。

赞(0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

阅读
分享

发表评论取消回复

快捷回复:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog

评论列表 (有 3 条评论,1763人围观)参与讨论
网友昵称:碧桂园十里银滩
碧桂园十里银滩 游客 Google Chrome 69.0.3947.100 Windows 10 x64 沙发
2020-03-04 回复
学习了!支持一下!
网友昵称:搬瓦工
搬瓦工 游客 Google Chrome 80.0.3987.87 Windows 10 x64 椅子
2020-03-06 回复
访问速度是基础,楼主分享的技巧很不错哦
网友昵称:boke112导航
boke112导航 游客 Google Chrome 80.0.3987.87 Windows 10 x64 板凳
2020-03-06 回复
博主,你好,boke112导航(博客导航站)特来拜会,发现贵站不错,已将贵站收录到博客导航的生活日记类,如有异议请留言哦!谢谢!PS:由于找不到贵站的留言板,所以就在此留言告知了,如造成困扰可删除本条评论,谢谢!