最小化响应/请求数据包
我想缩小通过 AJAX 来回发送的数据,以便它发送/接收更少的数据。
我将在每个响应/请求之前/之后解/压缩服务器端(C#)和客户端(Javascript)。
做到这一点最简单的方法是什么?
所有通信都是通过 JSON 字符串(请求和响应)完成的。
I want to shrink the data that is sent back and forth via AJAX, so that it sends/receives less data.
I will de/compress server-side (C#) and client-side (Javascript), before/after every response/request.
What would be the simplest way to do this?
All communications is done via JSON strings (both request and response).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的方法是在服务器上打开 http 压缩,然后让 IIS 和浏览器来解决。
The simplest way to do this is turn http compression on on your server and let IIS and the browser figure it out.
这里最简单的事情就是简单地启用现有 JSON 的 http 压缩。
不过,你可能会变得更加激进 - 例如,我还没有玩过它,但几周前有人提到了 javascript 协议缓冲区实现。让您的服务器返回一些原始字节(或者可能是 base-64 或十六进制),您可以看到一些显着的节省。不过,这将涉及对您的代码进行相当多的更改。
警告:虽然我通常非常熟悉protobufs,但我没有使用过该javascript实现。 YMMV。
The simplest thing here would be to simply enable http compression of your existing JSON.
You could possibly get more aggressive with it though - for example, I haven't played with it but a few weeks ago somebody mentioned a javascript protocol buffers implementation. Have your server return some raw bytes (or maybe base-64 or hex) and you could see some significant savings. It would involve changing your code quite a bit, though.
Caveat: although I'm pretty familiar with protobufs generally, I have not used that javascript implementation. YMMV.
我不建议您通过 JSON 发送太多数据,但如果确实有必要,我建议您对数据进行 GZIP 压缩。
这里有一篇关于它的好文章:http://www.west-wind。 com/Weblog/posts/10564.aspx
使用 GZIPED 数据,您最多可以节省 90%
I would not advise you to have too many data sent via JSON, but if it's really necessary, I'd suggest you GZIP your data.
There's a nice article about it here: http://www.west-wind.com/Weblog/posts/10564.aspx
With data GZIPED, you can save up to 90%
1
您可以在服务器端将“Content-encoding”设置为“gzip”以对 HTTP Flux 进行编码:
2
您可以在客户端和服务器端手动压缩 JSON:
对于客户端,您可以使用如下库: http://jszip.stuartk.co.uk/
对于服务器大小,您可以使用.Net框架来压缩/解压缩
1
You can set "Content-encoding" to "gzip" in server side to encode the HTTP flux:
2
You can manually Zip your JSON in client and server side :
For client side you can use a library like : http://jszip.stuartk.co.uk/
For server size you can use .Net framework to compress / decompress