ZIP压缩其实就是将网页内容压缩,减少HTML代码网络传输的代价,来提高Web性能.
请求的过程如下:
1:客户端Request请求。Http_header中会根据相应的浏览器发送相应的编码规则
Accept:*/*
Accept-Encoding:gzip,defate
User-Agent:OpenWave
这表明“我”客户端浏览器可以支持gzip、deflate两种压缩格式。
2:服务器端接受到这个“Accept-Encodeing”,服务器就可以采用相应的gizp、defalte,压缩web内容,并
Response。如:
Date: Mon, 19 Oct 2009 10:07:16 GMT
Server: Apache/2.2.8 (Win32) DAV/2 SVN/1.4.6 PHP/5.2.6
X-Powered-By: PHP/5.2.6
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 3871
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
3:客户端浏览器接受到相应压缩后的内容,根据"Content-Encoding:gzip",进行相应解压缩,并呈现给用户
Apache配置过程如下:
1.开启mod_headers模块
LoadModule headers_module modules/mod_headers.so
2.开启mod_deflate模块
LoadModule deflate_module modules/mod_deflate.so
3.配置mod_deflate模块,让其压缩html xml css php js等文件:
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-httpd-php application/x-javascript
AddOutputFilter DEFLATE html xml css php js
</ifmodule>
4.重启apche在phpinfo页面中能找到如:Accept-Encoding gzip,deflate 等表示配置成功
你还可通过firefox的插件YSlow查看文件的原始大小和通过gzip压缩后的大小
网站性能优化之Gzip压缩
最新推荐文章于 2024-05-04 23:24:04 发布