Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GZIP Automatically Decompressed by Browser?

I have enabled gzip compression in IIS 8.0 by following the url Enabling Gzip in IIS on Windows 8 I am calling external rest services from my application via jquery ajax call and C# code, currently my external web service is not gzip compressed. If i ask my service partner to gzip their response, do i need to write any decompression logic in my code on jquery side and c# side or browser automatically decompress the response for me ?

like image 452
user5075511 Avatar asked Aug 23 '15 23:08

user5075511


People also ask

Is gzip supported by all browsers?

gzip compressionThis HTTP header is supported in effectively all browsers.

How does browser gzip work?

Using gzip on the WebWhen a browser with gzip support sends a request, it adds “gzip” to its Accept-Encoding header. When the web server receives the request, it generates the response as normal, then checks the Accept-Encoding header to determine how to encode the response.

How do I know if gzip is enabled in Chrome?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled.


1 Answers

All modern browsers can handle a gzip encoded response. In fact, if you look at their requests, they'll have a header that says something along the lines of Accept-Encoding: gzip which is their way of saying to the server that they can handle gzipped responses.

The important part is that your server can return both gzip and uncompressed responses depending on the existence and value of that header. If a client doesn't send the Accept-Encoding header, you shouldn't compress it. If the client does send it, you can optionally encode the response using gzip. Not all content needs to be compressed as it may already be compressed and you're wasting CPU cycles. JPEG images are usually a good example of this. Most likely, IIS is making an intelligent decision here as well and only compressing what is necessary, when necessary.

You can verify IIS is doing what it should be by looking at the response headers coming back from your server and looking for the Content-Encoding: gzip header. That tells the client, or browser, that the content is encoded using gzip compression and it should decompress it appropriately.

All browser based requests (e.g., XHR/AJAX/jQuery, regular requests) will automatically be decompressed without additional effort from you. The browser is the client responsible for determining if it can handle gzip and will add the Accept-Encoding header if it does. Your JavaScript code will receive the uncompressed version of it in your response handler.

TL;DR: Turning it on is usually a good idea and you shouldn't need to do additional work.

like image 74
Marc Baumbach Avatar answered Oct 11 '22 01:10

Marc Baumbach