0

I've learned that for gzipping css and js files on the fly, it's best to keep the default level -1.

Now I'm serving static pre-compressed gzip files and I wonder if it's better to use a higher level for creating these.

Is level -9 ok then? Or should I use 4 or 5 as some even suggest to use for gzipping on the fly?

Well, it all comes down to the question if decompressing a highly compressioned file takes the same time as compressing it.

2 Answers 2

2

For on-the-fly real-time compression there is simply a question of diminishing returns; at some point the CPU penalty for a smaller download won't benefit you and your users in regards of a faster download.

I.e. when it takes 20 seconds to compress a download an additional 1% which will shave off 2 seconds of download time the effect is even detrimental.

Do the math on your own files, but this table seems to indicate that:

For a higher compression level the penalty appears mostly a one-off, only incurred at the time of compression, as de-compressing a gzip file becomes more efficient and faster at the highest compression levels.

For pre-compressed files, go as high as you can! You will save on bandwidth, download time and decompression times.

5
  • Thanks. "One interesting thing is that gzip and lzma decompress the faster the smaller the compressed size is" Indeed.
    – Martin
    Sep 5, 2015 at 18:30
  • Compressing of precompressed file is just a waste of time, CPU and RAM.
    – Kondybas
    Sep 5, 2015 at 18:41
  • Nobody talks about compressing of pre-compressed files here. I asked at what gzip compression level I should create the pre-compressed files.
    – Martin
    Sep 5, 2015 at 18:43
  • @Kondybas I hadn't read that interpretation from the question! Of course you're right compressing twice is senseless., but I wasn't suggesting doing such.
    – HBruijn
    Sep 5, 2015 at 18:43
  • Serving pre-comressed gzip files: google.de/…
    – Martin
    Sep 5, 2015 at 19:28
-2

Already compressed file can't be efficiently compressed again, even if it was compressed with low level of compression. That is what Shannon have told.

lower compression does not mean lower final entropy but rather smaller encoding table, 4hat mean lower CPU and RAM consumption as well as bigger resulting file.

It is easy to ensure that once compressed file can't be shrinked more. Precompressed files should be archived (by tar f.e.) or zipped/7z-ed/rared with zero compression, if tar is unavailable.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .