Why I should not compress images in HTTP headers?

Images such as GIF, JPEG or PNG are already compressed via highly specialized algorithms that achieve better result than general purpose algorithms such as deflate.

Therefore, re-compressing them yields little to no gain in size, and can even make files bigger, with the added cost of server-side processing.

So, in other words... do not compress images.


Your images should already be compressed - any extra compression won't have any noticeable effect on filesize, but will increase processing time.

  • .png files use DEFLATE compression already.
  • .jpg files generally use lossy compression.
  • .gif files use LZW compression.

Compressing files that have already been compressed very rarely results in a reduction in filesize, and can often increase filesize.