使用MVC3启用gzip压缩

时间:2012-09-29 18:44:42

标签: asp.net asp.net-mvc iis gzip http-compression

我正在使用Chrome扩展程序YSlow来测试我的网站性能。

我使用gzip在Compress组件上获得了F等级。

应该压缩发送15个纯文本组件:

http://localhost:21964/Content/custom/css/blog.css
http://localhost:21964/Content/custom/css/style.css
http://localhost:21964/Content/custom/css/socialize-bookmarks.css
http://localhost:21964/Content/custom/css/prettyPhoto.css
http://localhost:21964/Content/custom/css/flexslider.css
http://localhost:21964/Content/custom/css/colors/color-orange.css
http://localhost:21964/Content/sc2.css
http://localhost:21964/Content/custom/javascript/custom.js
http://localhost:21964/Content/custom/javascript/header.js
http://localhost:21964/Content/custom/javascript/twitter.js
http://localhost:21964/Content/custom/javascript/bra.photostream.js
http://localhost:21964/Content/custom/javascript/jquery.flexslider.js
http://localhost:21964/Content/custom/javascript/jquery.bpopup-0.7.0.min.js
http://localhost:21964/Content/custom/javascript/prettyPhoto.js
http://localhost:21964/css/colors/color-orange.css

压缩通过减少HTTP响应的大小来缩短响应时间。 Gzip是目前最流行和最有效的压缩方法,通常可将响应大小减少约70%。今天大约90%的互联网流量通过声称支持gzip的浏览器传播。

有一个类似的帖子here,但即使我按照这些步骤操作,它也不会压缩流量。

我已经完成的步骤:

  1. 我勾选了IIS中的所有压缩设置 - >压缩。
  2. 激活Windows功能“动态内容压缩”。
  3. 我已将此行添加到web.config
  4. <system.webServer>
    ...
     <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/javascript" enabled="true"/>
         <add mimeType="*/*" enabled="true"/>
       </dynamicTypes>
       <staticTypes>
         <add mimeType="text/*" enabled="true"/>
         <add mimeType="message/*" enabled="true"/>
         <add mimeType="application/javascript" enabled="true"/>
         <add mimeType="*/*" enabled="true"/>
       </staticTypes>
     </httpCompression>
     <urlCompression doStaticCompression="true" doDynamicCompression="true" /> 
    ...
    </system.webServer>
    

    <system.webServer> ... <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/javascript" enabled="true"/> <add mimeType="*/*" enabled="true"/> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true"/> <add mimeType="message/*" enabled="true"/> <add mimeType="application/javascript" enabled="true"/> <add mimeType="*/*" enabled="true"/> </staticTypes> </httpCompression> <urlCompression doStaticCompression="true" doDynamicCompression="true" /> ... </system.webServer>

    我目前正在项目中使用Developer Server - &gt;网络 - &gt;服务器

1 个答案:

答案 0 :(得分:2)

visual studio开发服务器(Cassini)不支持使用IIS或IIS Express进行gzip压缩。