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

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

问题描述

我正在尝试对来自 ASMX Web 服务的 JSON 响应进行 gzip 压缩,以供 jQuery 在客户端使用.

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

我的 web.config 已经像这样设置了 httpCompression:(我使用的是 IIS 7)

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

<httpCompression directory="%SystemDrive%inetpub	empIIS 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"/>

通过 fiddler,我可以看到正常的 aspx 和其他压缩工作正常.然而,jQuery ajax 请求和响应正常工作,只是没有被压缩.

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.

我错过了什么?

推荐答案

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

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

和您一样,我先尝试在 web.config 中更改它,但是没有用.只有当我将以下几行添加到 C:WindowsSystem32inetsrvconfigapplicationHost.config 时,它才起作用:

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>

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

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