What is gZip compression?
Asked Answered
S

3

71

I have heard a lot that one should use gZip for their webpages for faster access and downloads, and that it also saves the bandwidth.

So what is this gZip compression and how does it make the downloads faster ? Does it compress the HTML and images or just the HTML.

If I am to start using gZip in my webapps what considerations do I need to make ? Are there any server or browser restrictions for it, or does it support a particular encoding only.

Staffman answered 22/5, 2013 at 12:15 Comment(1)
Take full knowledge here. en.wikipedia.org/wiki/GzipShamefaced
S
78

GZip is a form of data compression -- i.e. it takes a chunk of data and makes it smaller. The original data can be restored by un-zipping the compressed file.

It is relevant to web apps and websites because the HTTP protocol includes the ability to gzip data that is being sent.

This means that, when it is in use, your bandwidth costs for serving the site will be lower because people visiting the site will be downloading smaller files.

There are a few caveats to using GZip, but, overall, it's usually better to use gzip than not to -- for example, it does take time and processor power to zip and unzip the files, but, typically, this is not a problem because the time it takes to do that is often less than the time that is saved by downloading a larger file. Therefore, the overall effect is time-saving despite the browser having to unzip the file.

GZip can compress all files; it doesn't make any difference what the file type is or the encoding. Obviously, some files can be compressed more effectively than others, so the bandwidth saving will vary - text files like HTML give the best results; images are not compressed so much by gzip because they already have some compression built-in. Some files (e.g. those that are already heavily compressed like .zip files) may actually get slightly bigger when gzipped because they can't be compressed any further but gzip still needs to add its metadata to the file. But these are edge cases and don't make much difference.

GZip across HTTP normally happens completely transparently. The end-user should be completely unaware that it is happening; the browser would do it behind the scenes for them. And from the webserver end, it is simply a matter of turning on a config setting in your web server software. From your perspective, that's really all you need to know; just set the gzip setting on your server (or ask your ISP to do it). It's quite possible it may already be active on your site without you even knowing.

Superfecundation answered 22/5, 2013 at 13:18 Comment(4)
@Staffman - no, all browsers support it. And even with browsers that don't support it, they should still work -- it's part of the HTTP 1.1 spec that the client specifies what kind of compression it supports, and the server will respond accordingly (ie if the browser says "I can't do gzip", the server won't send gzipped files. As I recall, there was a bug in early versions of IE6 that would break gzip, but web servers implemented work-arounds for that, and IE6 itself was fixed in WinXP SP2, so there really aren't going to be many people still using the broken version.Superfecundation
Yes, but a) all common browsers and servers support it, and b) compression is negotiated between the browser and server for each transaction, so any lack of support by uncommon clients is handled automatically.Ambulacrum
So computers are fast but the internet is slow, so we want to send a smaller file over the wire. But if it's a fast server and I have a good internet speed and I'm using an android phone with a slow CPU, could gzip cause a slower web page load? Does decompression ever take longer than downloading?Ivatts
@Curtis: Does decompression ever take longer than downloading? No. Not for any practical example. The only things where the gzip is not worth it are files that are already heavily compressed.Superfecundation
T
5

GZip compress files like HTML, JavaScript and CSS while serving request to the browser. As size of the file is reduced, it is served to the user in a faster manner. Not all browser support compression but now all modern browser support it. It is highly recommended to use Gzip, but it has a downside, which is increasing the CPU usage of the server which may be a concern sometimes. Using Gzip with client side caching will help in increased performance.

Tetrafluoroethylene answered 22/5, 2013 at 12:19 Comment(1)
If you are providing a text information which is very brief, you can add it to the comment area just below where the user has asked his question. Provide descriptive details with comprehensiveness as well as illustrative examples here that can help the user as well as individuals coming to know about this question. Thnx. - @TetrafluoroethyleneShamefaced
U
0

Gzip is a method to compress JavaScript and CSS to increase web page speed. Ultimately our website load time decreased with an overall speed increase.

Unbalance answered 27/1, 2020 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.