1

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

  • tncreased scalability (reduced server load).
  • Less network bandwidth (lower cost).
  • Better user experience (faster).

I want to compress the response. Something like .gzip format. Based on so tests, this is the size of an ajax response:

enter image description here

And this is the size of an ajax response which is zipped:

enter image description here

See? There is a huge different between them in theirs sizes.


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?

stack
  • 8,752
  • 9
  • 54
  • 91

2 Answers2

0

You should use Lz-string method to compress data and send using ajax call and at the time of response, again use it by decompressing it

GITHUB links : https://github.com/pieroxy/lz-string/

Documentation & usage : https://coderwall.com/p/mekopw/jsonc-compress-your-json-data-up-to-80

0

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:

  1. StackOverflow: Why Use Deflate Instead of Gzip for Text Files Served by Apache
  2. StackOverflow: Is There Any Performance Hit Involved In Choosing Gzip Over Deflate For- HTTP.com
  3. Wikpedia: Deflate
  4. Wikipedia: Gzip
  5. Article: How to Optimize Your Site with GZip Compression
  6. RFC: Deflate
Community
  • 1
  • 1
Clomp
  • 2,580
  • 1
  • 18
  • 34