Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

iis 7 - Compressing a web service response for jQuery

I'm attempting to gzip a JSON response from an ASMX web service to be consumed on the client-side by jQuery.

My web.config already has httpCompression set like so: (I'm using IIS 7)

<httpCompression directory="%SystemDrive%inetpubempIIS Temporary Compressed Files" 
    staticCompressionDisableCpuUsage="90" staticCompressionEnableCpuUsage="60" 
    dynamicCompressionDisableCpuUsage="80" dynamicCompressionEnableCpuUsage="50">
    <dynamicTypes>
        <add mimeType="application/javascript" enabled="true"/>
        <add mimeType="application/x-javascript" enabled="true"/>
        <add mimeType="text/css" enabled="true"/>
        <add mimeType="video/x-flv" enabled="true"/>
        <add mimeType="application/x-shockwave-flash" enabled="true"/>
        <add mimeType="text/javascript" enabled="true"/>
        <add mimeType="text/*" enabled="true"/>
        <add mimeType="application/json; charset=utf-8" enabled="true"/>
    </dynamicTypes>
    <staticTypes>
        <add mimeType="application/javascript" enabled="true"/>
        <add mimeType="application/x-javascript" enabled="true"/>
        <add mimeType="text/css" enabled="true"/>
        <add mimeType="video/x-flv" enabled="true"/>
        <add mimeType="application/x-shockwave-flash" enabled="true"/>
        <add mimeType="text/javascript" enabled="true"/>
        <add mimeType="text/*" enabled="true"/>
    </staticTypes>
    <scheme name="gzip" dll="%Windir%system32inetsrvgzip.dll"/>
</httpCompression>
<urlCompression doDynamicCompression="true" doStaticCompression="true"/>

Through fiddler I can see that normal aspx and other compressions work fine. However, the jQuery ajax request and response work as they should, only nothing gets compressed.

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can change httpCompression only in applicationHost.config. See this link

Like you, I tried changing it in web.config first, but it didn't work. It worked only when I added the following lines to C:WindowsSystem32inetsrvconfigapplicationHost.config:

  <dynamicTypes>
       ...
       <add mimeType="application/json" enabled="true" />
       <add mimeType="application/json; charset=utf-8" enabled="true" />
       ...
  </dynamicTypes>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...