IIS7.5开启GZip压缩

在IIS7.5选择要开启GZip压缩的网站,在功能视图中找到并双击"压缩"图标,在压缩界面中钩选"启用静态内容压缩"和"启用动态内容压缩",应用即可:



静态内容压缩和动态内容压缩的区别

静态内容压缩:压缩的静态响应可以缓存到磁盘上,供多个请求使用,同时不会降低 CPU 资源的性能。对于下一个请求,可以从磁盘检索压缩文件,由于 CPU 不必再次压缩文件,从而提高了性能。

动态内容压缩:压缩动态应用程序响应会影响 CPU 资源,因为 IIS 不缓存动态输出的压缩版本。如果对动态响应启用了压缩,那么当 IIS 每次收到对包含动态内容的资源的请求时,都会发送新压缩的响应。因为动态压缩会消耗大量的 CPU 时间和内存资源,所以应当仅在满足下列条件的服务器上使用它:客户端的网络连接速度很慢,但有多余的 CPU 时间。

配置需要启用压缩的文件类型

打开C:\Windows\System32\inetsrv\config\applicationhost.config,找到以下内容:

引用内容 引用内容
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

在dynamicTypes节点下添加要启用动态内容压缩的文件mime,在staticTypes节点下添加要启用静态内容压缩的文件mime。

补充说明

当要压缩的文件内容很小时,压缩效果会不明显,甚至会出现压缩后的大小比压缩前大。

压缩前:
引用内容 引用内容
Cache-Control:private
Content-Length:592
Content-Type:application/json; charset=utf-8
Date:Thu, 27 Sep 2012 03:34:10 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET

压缩后:
引用内容 引用内容
Cache-Control:private
Content-Encoding:gzip
Content-Length:705
Content-Type:application/json; charset=utf-8
Date:Thu, 27 Sep 2012 03:35:24 GMT
Server:Microsoft-IIS/7.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET


评论: 0 | 引用: 0 | 查看次数: 5669
发表评论
登录后再发表评论!