压缩jQuery的Web服务响应 [英] Compressing a web service response for jQuery

查看:210
本文介绍了压缩jQuery的Web服务响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试从一个ASMX Web服务中压缩JSON响应,以便在客户端使用jQuery。我的web.config已经有httpCompression设置像这样:(我使用IIS 7)

 < httpCompression directory =%SystemDrive%\inetpub temp \IIS Temporary Compressed Files
staticCompressionDisableCpUUsage =90staticCompressionEnableCpuUsage =60
dynamicCompressionDisableCpuUsage =80dynamicCompressionEnableCpUUsage =50>
< dynamicTypes>
< add mimeType =application / javascriptenabled =true/>
< add mimeType =application / x-javascriptenabled =true/>
< add mimeType =text / cssenabled =true/>
< add mimeType =video / x-flvenabled =true/>
< add mimeType =application / x-shockwave-flashenabled =true/>
< add mimeType =text / javascriptenabled =true/>
< add mimeType =text / *enabled =true/>
< add mimeType =application / json; charset = utf-8enabled =true/>
< / dynamicTypes>
< staticTypes>
< add mimeType =application / javascriptenabled =true/>
< add mimeType =application / x-javascriptenabled =true/>
< add mimeType =text / cssenabled =true/>
< add mimeType =video / x-flvenabled =true/>
< add mimeType =application / x-shockwave-flashenabled =true/>
< add mimeType =text / javascriptenabled =true/>
< add mimeType =text / *enabled =true/>
< / staticTypes>
< scheme name =gzipdll =%Windir%\system32\inetsrv\gzip.dll/>
< / httpCompression>
< urlCompression doDynamicCompression =truedoStaticCompression =true/>



通过fiddler我可以看到正常的aspx和其他压缩工作正常。



我缺少什么?

解决方案

您只能在 applicationHost.config 中更改 httpCompression
请参见此链接



像你一样,我尝试在 web.config 中更改它,但它没有工作。它只有当我添加以下行到 C:\Windows \System32\inetsrv\config\applicationHost.config

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


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%\inetpub\temp\IIS 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%\system32\inetsrv\gzip.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?

解决方案

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:\Windows\System32\inetsrv\config\applicationHost.config:

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

这篇关于压缩jQuery的Web服务响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆