7

I'm posting a json string to my server however I'm wondering if there is a way to post this string compressed with gzip? the content-length is 24kb which is the same size as if I pick the posted JSON and paste it on a textfile so it obviously is not being compressed.

ryudice
  • 36,476
  • 32
  • 115
  • 163

2 Answers2

1

You could use some JS library to compress the data, for example this Huffman compression implementation. However the added slowness of the compression might very well offset the time you save in upload speed. You have to try it and make that decision for yourself, but in general this sounds like it's not worth it. Especially since it means loading more JS code, which creates slower page load time.

Unfortunately the browsers do not provide APIs to any compression algorithms. So you can't use a fast built-in implementation.

Seldaek
  • 40,986
  • 9
  • 97
  • 77
-1

Actually when server sends the response compressed in gzip , its because in request client announces to the server using http-encoding, what compressed formats it can accept. Thats why server compresses and sends the response because it knows through request that client can handle gzip etc.

Now clients assumption that server can handle a compressed request , i am not sure about that.

OK i found this

Can I compress HTTP Requests using GZIP?

Community
  • 1
  • 1
Rizwan Sharif
  • 1,089
  • 2
  • 10
  • 20