而现在的浏览器几乎都支持 GZip 和 Deflate 压缩,
因此在传输一些大的JS或CSS文件(如EXTJS)时对它进行压缩则可以减少下载时间,
从而提高加载速度。
===========
对比一下使用情况
===========
使用:Accept-Encoding:gzip,deflate
HTTP/1.0 200 OK
Date: Fri, 24 Oct 2008 00:13:38 GMT
Server: Apache
Last-Modified: Fri, 24 Oct 2008 00:10:51 GMT
ETag: "5c406-459f49d3178c0"-gzip
Accept-Ranges: bytes
X-Powered-By: mod_xlayout_jh/0.0.1vhs.markIII.remix
Cache-Control: max-age=60
Expires: Fri, 24 Oct 2008 00:14:38 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/html
Age: 51
Content-Length: 90255
X-Cache: HIT from nanjing75-169.HP08040113.sina.com.cn
Via: 1.0 nanjing75-169.HP08040113.sina.com.cn:80 (squid/2.6.STABLE13)
Connection: close
--------------------未使用Accept-Encoding
HTTP/1.0 200 OK
Date: Fri, 24 Oct 2008 00:11:31 GMT
Server: Apache
Last-Modified: Fri, 24 Oct 2008 00:10:51 GMT
ETag: "5c406-459f49d3178c0"
Accept-Ranges: bytes
X-Powered-By: mod_xlayout_jh/0.0.1vhs.markIII.remix
Cache-Control: max-age=60
Expires: Fri, 24 Oct 2008 00:12:31 GMT
Vary: Accept-Encoding
Content-Length: 389863
Content-Type: text/html
Age: 51
X-Cache: HIT from nanjing75-167.HP08040111.sina.com.cn
Via: 1.0 nanjing75-167.HP08040111.sina.com.cn:80 (squid/2.6.STABLE13)
Connection: close
===========
在DotNet2.0中提供了GZip和Deflate压缩算法,
自定义一个 CompressionHttpHandler,
实现 System.Web.IHttpHandler 接口.
首先取得请求的路径,然后判断浏览器返回的服务端标头是否使用GZip压缩,
如果使用,则设置Content-encoding为gzip,
然后设置输出的stream用GZip解压缩的,
最后将文件写入到HTML文本中。
另:GZip.gz,Deflate.de,
经测试(几大网站),GZIP可用,Deflate始终未起作为,跟服务端设置有关.
参考这段也行:http://blog.csdn.net/wszhoho/archive/2008/04/24/2323698.aspx
http://www.wintle.cn/article.asp?id=342
结论:
[ 本帖最后由 faunus 于 2008-10-29 21:09 编辑 ] |