使用Apache模块mod_deflate加快页面打开速度
2012-06-26 16:54
531 查看
mod_deflate 模块提供了
修改httpd.conf
1.使用此模块
LoadModule deflate_module modules/mod_deflate.so
2.在conf文件底下加上
#set deflate modules
#<ifmodule mod_deflate.c>
#DeflateCompressionLevel 9 #设置压缩率
#AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
#AddOutputFilter DEFLATE css js
#</ifmodule>
#以上设置,经过测试后感觉不太好,没有对css和js文件进行压缩。
<location />
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilter DEFLATE css #压缩css文件
AddOutputFilter DEFLATE js #压缩js文件
#BrowserMatch ^Mozilla/4 gzip-only-text/html
#BrowserMatch ^Mozilla/4\.0[678] no-gzip
#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html #针对不同浏览器的配置,这里用处不大
# Don't compress images #对照片文件不进行压缩处理
SetEnvIfNoCase Request_URI (?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI (?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
#SetEnvIfNoCase Request_URI .(css|js)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</location>
DeflateFilterNote Input input_info #设置日志输出!
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog logs/deflate_log.log deflate
以下是日志输出 deflate_log.log :
"GET /23413 HTTP/1.1" 206/268 (76%)
"GET /123 HTTP/1.1" 205/266 (77%)
"GET /favicon.ico HTTP/1.1" 209/274 (76%)
"GET / HTTP/1.1" 75/73 (102%)
"GET /new/index.jsp HTTP/1.1" 6155/27871 (22%)
"GET /new/css/index1.css HTTP/1.1" 2028/7958 (25%)
"GET /new/css/fonts.css HTTP/1.1" 212/279 (75%)
"GET /js/include.js HTTP/1.1" 2106/5425 (38%)
"GET /new/js/inc.js HTTP/1.1" 1264/3983 (31%)
"GET /search/js/search.js HTTP/1.1" 356/730 (48%)
"GET /search/js/selectarea.js HTTP/1.1" 27757/168335 (16%)
"GET /new/images/new/new_02.gif HTTP/1.1" -/- (-%)
"GET /new/images/new/new_16.gif HTTP/1.1" -/- (-%)
"GET /new/images/new/new_11.gif HTTP/1.1" -/- (-%)
"GET /new_iflogin?tt=1195799219343 HTTP/1.1" 4/2 (200%)
"GET /new/images/bian1.gif HTTP/1.1" -/- (-%)
"GET /new/js/5adpics.js HTTP/1.1" 1068/3845 (27%)
"GET /new/images/1.jpg HTTP/1.1" -/- (-%)
"GET /new/images/userimg_03.gif HTTP/1.1" -/- (-%)
"GET /new/images/4.jpg HTTP/1.1" -/- (-%)
可以看到除了图片jpg格式文件外,其他的jsp,css,js 等都进行了压缩处理!
DEFLATE输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽。
修改httpd.conf
1.使用此模块
LoadModule deflate_module modules/mod_deflate.so
2.在conf文件底下加上
#set deflate modules
#<ifmodule mod_deflate.c>
#DeflateCompressionLevel 9 #设置压缩率
#AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
#AddOutputFilter DEFLATE css js
#</ifmodule>
#以上设置,经过测试后感觉不太好,没有对css和js文件进行压缩。
<location />
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilter DEFLATE css #压缩css文件
AddOutputFilter DEFLATE js #压缩js文件
#BrowserMatch ^Mozilla/4 gzip-only-text/html
#BrowserMatch ^Mozilla/4\.0[678] no-gzip
#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html #针对不同浏览器的配置,这里用处不大
# Don't compress images #对照片文件不进行压缩处理
SetEnvIfNoCase Request_URI (?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI (?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
#SetEnvIfNoCase Request_URI .(css|js)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</location>
DeflateFilterNote Input input_info #设置日志输出!
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog logs/deflate_log.log deflate
以下是日志输出 deflate_log.log :
"GET /23413 HTTP/1.1" 206/268 (76%)
"GET /123 HTTP/1.1" 205/266 (77%)
"GET /favicon.ico HTTP/1.1" 209/274 (76%)
"GET / HTTP/1.1" 75/73 (102%)
"GET /new/index.jsp HTTP/1.1" 6155/27871 (22%)
"GET /new/css/index1.css HTTP/1.1" 2028/7958 (25%)
"GET /new/css/fonts.css HTTP/1.1" 212/279 (75%)
"GET /js/include.js HTTP/1.1" 2106/5425 (38%)
"GET /new/js/inc.js HTTP/1.1" 1264/3983 (31%)
"GET /search/js/search.js HTTP/1.1" 356/730 (48%)
"GET /search/js/selectarea.js HTTP/1.1" 27757/168335 (16%)
"GET /new/images/new/new_02.gif HTTP/1.1" -/- (-%)
"GET /new/images/new/new_16.gif HTTP/1.1" -/- (-%)
"GET /new/images/new/new_11.gif HTTP/1.1" -/- (-%)
"GET /new_iflogin?tt=1195799219343 HTTP/1.1" 4/2 (200%)
"GET /new/images/bian1.gif HTTP/1.1" -/- (-%)
"GET /new/js/5adpics.js HTTP/1.1" 1068/3845 (27%)
"GET /new/images/1.jpg HTTP/1.1" -/- (-%)
"GET /new/images/userimg_03.gif HTTP/1.1" -/- (-%)
"GET /new/images/4.jpg HTTP/1.1" -/- (-%)
可以看到除了图片jpg格式文件外,其他的jsp,css,js 等都进行了压缩处理!
相关文章推荐
- Apache使用mod_deflate模块压缩页面优化传输速度
- Apache 使用gzip、deflate 压缩页面加快网站访问速度
- 【页面加速】配置Nginx加载ngx_pagespeed模块,加快网站打开的速度
- Apache两个模块mod-expires和mod_deflate的使用
- Apache: 使用mod_deflate模块启用gzip功能
- Apache使用mod_deflate模块启用gzip功能
- apache mod_deflate 模块使用总结
- Apache在Windows下使用Mod_rewrite模块
- 使用apache mod_env模块保存php程序敏感信息
- 使用apache Rewrite_mod模块完成URL重写
- apache 页面压缩技术mod_deflate安装和配置
- Apache在Windows下使用Mod_rewrite模块
- Effective前端7:加快页面打开速度
- apache 使用 mod_fcgid.so模块时 配置指令
- apache通过mod_deflate打开gzip
- 使用apache mod_env模块保存php程序敏感信息
- JS延迟加载加快页面打开速度示例代码
- 加快页面加载速度的解决方案-asp.net使用httphandler打包多CSS或JS文件
- 使用e-tag来加快页面加载速度和提高用户体验
- apache mod_vhost_alias模块使用