如何压缩ajax请求的响应? [英] How can I compress the response of an ajax request?
问题描述
我返回整个HTML作为ajax请求的响应(不仅仅是一个JSON数组).如您所知,响应(比JSON)大一些.因为它包含更多的东西,例如html标记,html属性等,所以
I return the whole HTML as the response of an ajax request (not just an array as JSON). So as you know, the response will be larger a bit (than JSON). Because it contains some more things like html tags, html attributes etc ... So to
- 提高了可扩展性(减少了服务器负载).
- 较少的网络带宽(较低的成本).
- 更好的用户体验(更快).
我想压缩响应.类似于.gzip
格式.根据so测试,这是ajax响应的大小:
I want to compress the response. Something like .gzip
format. Based on so tests, this is the size of an ajax response:
这是压缩的ajax响应的大小:
And this is the size of an ajax response which is zipped:
看到了吗?它们之间的大小差异很大.
See? There is a huge different between them in theirs sizes.
我想知道的是,是否可以压缩ajax请求的响应并将其转换为客户端的常规文本?为此,我需要对Web服务(如nginx)配置进行一些更改吗?还是自动执行?
All I want to know, is it possible to compress the response of an ajax request on the way and convert it to a regular text on the client side? For doing that do I need to do some changes in the web service (like nginx) configuration? Or it does that automatically?
推荐答案
您可能想查看其他一些StackOverflow帖子,以及Wikipedia链接&网络上有关Deflate&的文章Gzip.这里有一些链接供您仔细阅读.他们有一些有趣的图表其中的信息:
You may want to check out some of the other StackOverflow posts, plus Wikipedia links & articles on the web regarding Deflate & Gzip. Here are some links for you to peruse. They have some interesting charts & information in them:
- StackOverflow:为什么使用Deflate代替Gzip压缩Apache提供的文本文件
- StackOverflow :是否在选择Def时的Gzip压缩中涉及任何性能问题? HTTP.com
- Wikpedia:放气
- 维基百科:Gzip
- 文章:如何使用GZip压缩
- RFC:缩小
- StackOverflow: Why Use Deflate Instead of Gzip for Text Files Served by Apache
- StackOverflow: Is There Any Performance Hit Involved In Choosing Gzip Over Deflate For- HTTP.com
- Wikpedia: Deflate
- Wikipedia: Gzip
- Article: How to Optimize Your Site with GZip Compression
- RFC: Deflate
这篇关于如何压缩ajax请求的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!