开发者

Why I should not compress images in HTTP headers?

开发者 https://www.devze.com 2023-02-09 13:24 出处:网络
I read some articles about HTTP headers compression. Today I installe开发者_JAVA技巧d YSlow and it recommends that I compress the resources (text/html, javascript, css and images). Now I\'m reading th

I read some articles about HTTP headers compression. Today I installe开发者_JAVA技巧d YSlow and it recommends that I compress the resources (text/html, javascript, css and images). Now I'm reading the documentation for Apache mod_deflate but in the example don't compress images.

Should I or should I not compress images in my site?


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.


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.


SVGs should be compressed by Apache mod_deflate as

AddType image/svg+xml svg

AddOutputFilterByType DEFLATE image/svg+xml

More information at https://httpd.apache.org/docs/2.4/mod/mod_deflate.html.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号