1

I have an already optimized JPEG image in my server 32.07 kB (and in my local computer), 800px * 534px, if I request it via browser, it keeps the same width * height, but its size gets smaller 17,97 Ko and becomes pixelated.

I checked Apache configuration:

# LoadModule deflate_module modules/mod_deflate.so

Response Headers:

HTTP/1.1 200 OK
Date: Sat, 30 Jan 2016 11:31:50 GMT
Server: Apache
Last-Modified: Sat, 26 Dec 2015 11:56:02 GMT
ETag: "804c-527cbc1833880"
Accept-Ranges: bytes
Content-Length: 32844
Content-Type: image/jpeg
Connection: keep-alive

I am working on a LAMP environment installed on a VPS server. I sent a ticket to OVH to ask them if they are compressing images on a superior level, but still waiting for a response.

Are there other places to inpect instead of Apache ?

Another thing, I can bet it's not related to browser, because I got the same result in Firefox and Chrome.

0

Compressed or Not Compressed

Content-Length: 32844 matches the size of your jpeg and there is no header saying the file is compressed. I assume you also tested this from your workstation?

How you verify

Use curl or wget to pull the image to your computer and validate the size has not changed, assuming your connection is HTTPS and nothing else can intercept the communication such as a proxy or anti-virus. Proxies can most certainly change the size of images.

Proxy Testing

Assuming you have mod_headers module in your apache installation, add the following to your apache config to tell Proxies to leave the file alone.

header set cache-control "private, max-age=0, no-cache, no-transform, no-store"
header set Pragma no-cache

This should go in a <Directory> section specific to the jpeg you are testing.

Keep in mind that any content served up with these headers will not be cached and performance will suffer. It may be worth reading up on cache-control headers.

  • I added the 2 headers, now the image is not pixelated, and the content-length is still the same. I wonder if it's possible to instruct proxies to disable further compression but still cache the images. – AFA Med Jan 30 '16 at 16:43
  • Yes, change private to public and remove all the other header options except for no-transform. Leave that one. – Aaron Jan 30 '16 at 17:22
  • Just for your knowledge, you can also set headers by Location, Files, FilesMatch in addition to Directory blocks. This can be useful if you have images you know will never change. I forgot to mention to also remove the Pragma no-cache header. – Aaron Jan 30 '16 at 17:30
  • OK good, I will give it a try and inspect caches – AFA Med Jan 30 '16 at 17:37
  • For this type of testing, you may also want to try out the HttpFox addon for Firefox. It makes looking at each request/response and whether or not cache was used much easier. – Aaron Jan 31 '16 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.