win2003+ iis 6 一键实现gzip

一.摘要

本文总结了如何为使用IIS托管的网站启用Gzip压缩, 从而减少网页网络传输大小, 提高用户显示页面的速度.

 

二.前言.

本文的知识点是从互联网收集整理, 主要来源于中文wiki.  使用YSlow检测网站启用了哪些优化时, Gzip是十分关键的一项. 启动Gip压缩将立竿见影的减少页面的网络传输大小.

 

三.HTTP压缩概述

HTTP压缩是在Web服务器和浏览器间传输压缩文本内容的方法。HTTP压缩采用通用的压缩算法如gzip等压缩HTML、JavaScript或CSS文件。压缩的最大好处就是降低了网络传输的数据量,从而提高客户端浏览器的访问速度。当然,同时也会增加一点点服务器的负担。Gzip是比较常见的一种HTTP压缩算法。

 

四.HTTP压缩工作原理

Web服务器处理HTTP压缩的工作原理如下:

1.Web服务器接收到浏览器的HTTP请求后,检查浏览器是否支持HTTP压缩;
在用户浏览器发送请求的HTTP头中,  带有"Accept-Encoding: gzip, deflate"参数则表明支持gzip和deflate两种压缩算法.

2.如果浏览器支持HTTP压缩,Web服务器检查请求文件的后缀名;
静态文件和动态文件后缀启动要所都需要在MetaBase.xml中设置.
静态文件需要设置: HcFileExtensions Metabase Property (单击跳转到MSDN说明)
动态文件需要设置: HcScriptFileExtensions Metabase Property (单击跳转到MSDN说明)

3.如果请求文件是HTML、CSS等静态文件并且文件后缀启用了压缩,则Web服务器到压缩缓冲目录中检查是否已经存在请求文件的最新压缩文件;

4.如果请求文件的压缩文件不存在,Web服务器向浏览器返回未压缩的请求文件,并在压缩缓冲目录中存放请求文件的压缩文件;

5.如果请求文件的最新压缩文件已经存在,则直接返回请求文件的压缩文件;

6.如果请求文件是ASPX等动态文件并且文件后缀启用了压缩,Web服务器动态压缩内容并返回浏览器,压缩内容不存放到压缩缓存目录中。

 

五.启用HTTP压缩

下载

IIS6-SET-GZIP.rar  执行CMD文件即可一步搞定

 

REM Setup IIsCompressionScheme for deflate
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcCompressionDll "%windir%\system32\inetsrv\gzip.dll"
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcCreateFlags 0
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoDynamicCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoOnDemandCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDoStaticCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel 9
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcFileExtensions "htm" "html" "txt" "js" "xml" "css"
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcOnDemandCompLevel 9
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcPriority 1
cscript adsutil.vbs set W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx"


REM Setup IIsCompressionScheme for GZip
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcCompressionDll "%windir%\system32\inetsrv\gzip.dll"
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcCreateFlags 1
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoDynamicCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoOnDemandCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDoStaticCompression TRUE
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel 9
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcFileExtensions "htm" "html" "txt" "js" "xml" "css"
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcOnDemandCompLevel 9
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcPriority 1
cscript adsutil.vbs set W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "aspx" "asmx"

REM Setup IIsCompressionSchemes parameters
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcCacheControlHeader max-age=86400
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcCompressionBufferSize 102400
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcCompressionDirectory "%windir%\IIS Temporary Compressed Files"
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcDoDiskSpaceLimiting FALSE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcDoDynamicCompression TRUE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcDoOnDemandCompression TRUE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcDoStaticCompression TRUE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcExpiresHeader "Wed, 01 Jan 1997 12:00:00 GMT"
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcFilesDeletedPerDiskFree 256
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcIoBufferSize 102400
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcMaxDiskSpaceUsage 0
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcMaxQueueLength 1000
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcMinFileSizeForComp 1
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcNoCompressionForHttp10 FALSE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcNoCompressionForProxies FALSE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcNoCompressionForRange FALSE
cscript adsutil.vbs set W3SVC/Filters/Compression/Parameters/HcSendCacheHeaders FALSE

iisreset


 

 

检测是否成功:http://gzip.zzbaike.com/

posted @ 2009-10-27 09:05  苔苔以苔苔以苔  阅读(756)  评论(0编辑  收藏  举报
猪先飞