Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 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 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...