Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How large does a file need to be to benefit from gzip compression?

Since gzip takes time to pack on the server side, and more time to unpack on the client side, how large does a file need to be in order to benefit from it?

Are there any real numbers out there that demonstrate the efficacy of gzip at common download speeds?

like image 520
Isaac Lubow Avatar asked Oct 13 '10 13:10

Isaac Lubow


People also ask

How much does gzip reduce file size?

Gzip, the most popular compression method, is used by web servers and browsers to seamlessly compress and decompress content as it's transmitted over the Internet. Used mostly on code and text files, gzip can reduce the size of JavaScript, CSS, and HTML files by up to 90%.

When should you not use gzip?

If you take a file that is 1300 bytes and compress it to 800 bytes, it's still transmitted in that same 1500 byte packet regardless, so you've gained nothing. That being the case, you should restrict the gzip compression to files with a size greater than a single packet, 1400 bytes (1.4KB) is a safe value.

Is there a limit for gzip?

GZIP has a size limitation of 4GB, got it from http://www.gzip.org/#faq10 There are some patches mentioned in the above link to be able to read a file more than 4gb.

How does gzip benefit compression?

Enabling gzip compression can reduce the size of the transferred response by up to 90%, which can significantly reduce the amount of time to download the resource, reduce data usage for the client, and improve the time to first render of your pages. See text compression with GZIP to learn more.


2 Answers

It will depend heavily in the nature of the data to be transferred (i.e. how much compressible is the data you are working on). If you are concerned about the time it takes to get the original file on the client side you should compare:

a) time taken to compress the file in the server + time taken to transfer the compressed file from the server to the client + time taken to decompress the file in the client

b) time taken to transfer the original (uncompressed) file from the server to the client.

I believe you would have to try and measure these figures using actual sample data of your application. For example, if you were dealing with video files (uncompressable) then it would probably be better just to send the file without compressing it. However, if for example, you were dealing with text files (highly compressable) then the overall time used for a) might be lower than b)

like image 148
gusbro Avatar answered Oct 12 '22 14:10

gusbro


Not very large, gzip compress text very well, even small. CPU is much cheaper than transfer. 1M file compressed to 100K will be downloaded ten times faster. You should not gzip jpgs,mp3 and any other already compressed data.

like image 40
baklarz2048 Avatar answered Oct 12 '22 12:10

baklarz2048