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

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

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

以下代码在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>

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

转载请注明:鸟儿博客 

文章声明:以上内容(如有图片或视频亦包括在内)除非注明,否则均为网站名称原创文章,转载或复制请以超链接形式并注明出处。https://xz.itlaoli.com/blog/127.html

« 上一篇
下一篇 »

相关推荐

Linux手动分区挂载10TB磁盘到 /www目录并安装宝塔面板到数据盘的完整教程

2025年10月16日

434阅读

记录Windows11系统暂停更新怎么延长周数的教程

2025年08月25日

2849阅读

Windows11失败,提示“ahsProtector-你的电脑上有服务尚未准备好用于此版本的Windows”的解决方案

2025年08月21日

3310阅读

zblogPHP李洋个人博客主题使用网址导航模板的图文教程

2025年05月27日

5605阅读

百度普通收录API提交后提示 {"error":400,"message":"site init fail"}问题怎么解决?

2025年03月03日

5066阅读

zblog应用中心后台无法更新主题模板及无法新建标签的解决办法

2025年02月24日

6606阅读

发表评论

访客 访客
评论列表 (有 5 条评论,11874人围观)
网友昵称:碧桂园十里银滩
碧桂园十里银滩 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:由于找不到贵站的留言板,所以就在此留言告知了,如造成困扰可删除本条评论,谢谢!
取消
微信二维码
微信二维码
支付宝二维码