cpu速度越来越快也更便宜,IDC机房带宽很昂贵,所以用cpu来换取带宽。
apche启用mod_deflate压缩:
<ifmodule mod_deflate.c>
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
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
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
nginx 启用gzip压缩:
http {
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css text/html application/xml;
}
压缩效果测试
不使用压缩:
curl http://veryi.com/w/1.html –silent –write-out "size_download=%{size_download}\n" –output /dev/null
size_download=64031
使用 Accept-Encoding 头:
curl http://veryi.com/w/1.html –silent -H "Accept-Encoding: gzip,deflate" –write-out "size_download=%{size_download}\n" –output /dev/null
size_download=20012
比较数字就可以知道压缩效果。
使用 HTTP 1.0 测试:
curl http://veryi.com/w/1.html –silent –http1.0 -H "Accept-Encoding: gzip,deflate" –write-out "size_download=%{size_download}\n" –output /dev/null
size_download=64031
参考:http://dev.nuclearrooster.com/2009/11/08/checking-gzipdeflate-server-responses-with-curl/
转