HTTP COMPRESSION HTTP 压缩实现 ,iis6

You can enable HTTP compression server-wide or on a specific directory. HTTP compression improves bandwidth utilization and speeds up Web site performance. In addition, you can compress static or dynamic responses.

你可以启用HTTP服务器端压缩,它可以提高你的带宽利用率,加速你的网站性能。另外,你也可以选择是压缩动态的还是静态的响应包。

有一点你不能忽略的是:以下的所有操作必须在具有管理员权限的帐号下操作。

操作步骤:

1 点击iis,网站,属性,服务,选择压缩应用程序(启用压缩动态文件),选择复选框,压缩静态文件夹的位置。这里有几点要说明一下:启用压缩动态文件,就是压缩的比如aspx,asp等动态文件,但是每次压缩都是实时的,所以对服务器的cpu占用是非常大的。推荐不选。压缩静态文件,iis只需要压缩静态文件一次,就保存在刚才指定的那个文件夹里面。Once a static file is compressed, it is cached in this temporary directory until it expires, or the content changes. The directory must be on the local drive of an NTFS–formatted partition.一旦静态文件压缩了,它就被缓存在临时文件夹里,直到它过期,内容改变。还有就是这个文件夹的所在的磁盘,必须是以NTFS格式的磁盘。

Under Maximum temporary directory size, click a folder size option. If you specify a maximum size under Limited to (in megabytes) (the default setting is 95 MB), then when the limit is reached, IIS automatically cleans up the temporary directory by applying the "least recently used" rule.

如果指定了最大的文件大小,那么如果一旦达到最大容量,那么iis就会自动地清除临时文件夹的东西,清楚原则是least recently used" rule,最近使用地最少的就清除掉。

To enable global HTTP compression by using Adsutil.vbs

1. Open a command prompt.

2. To enable dynamic compression, type the following at the command prompt and then press ENTER:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true

3. To enable static compression, type the following at the command prompt and then press ENTER:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

要启用全局的HTTP压缩,请使用ADSUTIL.Vbs.这种我并不是很推荐,也不喜欢。

1 打开命令窗口,

2 如果开启动态压缩,键入以下的命令参数,按回车:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true

3 启用静态压缩,键入以下命令,按回车:

cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

To enable HTTP Compression for Individual Sites and Site Elements

为单独网站或者网站元素提供HTTP压缩,请操作如下步骤:

1. To enable static compression for only a single directory, first disable global static compression (if it is enabled) and then enable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

1 启用单一的静态压缩文件夹,首先检查你是不是启用了全局的静态压缩,如果启用就要关闭它,接下来启用静态压缩一个文件夹。例如:下面的例子是启用http://www.contoso.com/Home/StyleSheets 这个文件夹的静态压缩,请按照下列步骤进行:

1.

Disable global static compression by executing the following command at a command prompt:

1 禁止全局压缩,通过命令提示中输入下列命令,

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression false

1.

Enable static compression at this directory by executing the following command at a command prompt:

启用静态压缩一个文件夹,执行以下的命令,在命令窗口中:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression true

2. To disable static compression for only a single directory, first enable global static compression (if it is disabled) and then disable static compression at that directory. For example, to enable static compression for a directory at http://www.contoso.com/Home/StyleSheets, perform the following steps:

2 要禁止为一个文件夹的静态压缩,第一步就是要启用全局的静态压缩,然后禁止掉为一个文件的静态压缩,请执行下列步骤:

1.

Disable global static compression by executing the following command at a command prompt:

1 禁止全局静态文件压缩,执行下列的命令:

adsutil set w3svc/filters/compression/parameters/HcDoStaticCompression true

1.

Enable static compression at this directory by executing the following command at a command prompt:

启用静态压缩一个文件夹,执行下列的命令:

adsutil set w3svc/1/root/Home/StyleSheets/DoStaticCompression false

以上都是基于iis6的。微软提供的这些都是基于命令窗口的操作,当然也可以可视化操作,直接在iis中启用了压缩,并且在C:\WINDOWS\system32\inetsrv目录中添加服务器扩展gzip.dll(iis服务器扩展) 后,再打开这个文件夹下的文件: C:\Windows\System32\inetsrv\MetaBase.xml,打开后查找Filters/Compression/gzip (这个文件就是iis的配置文件)在这个节点下,有

HcDoDynamicCompression,HcDoOnDemandCompression,HcDoStaticCompression,如果你要设置动态文件压缩,则启用第一个,设置为true,建议不要启用。如果要启用静态文件压缩,请设置后2个为true,然后指定他们各自的压缩程度: CompressionLevel,这个我的指定是100,然后指定压缩的静态文件的后缀名类型,我指定的是css,js,xml .指定完后需要停止iis服务,在windows服务中停止。停止后保存。然后你就可以到fiddler中观察到你的一些文件被压缩了。

我在我们网站的压缩应用,使得我的一个200KB的JS文件压缩成了20KB!!!效率非常高的!