Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_expires not setting cache-control headers on JPEG images

I can't figure out why plain old JPEG images (about a dozen, < 10 KB each) in a website I'm working on won't take the cache-control headers they're being force feed. The .htaccess rules I'm using are based off the most recent HTML5 Boilerplate .htaccess file (relevant section below). What's weird is there's about the same amount of PNGs in the site and, except for two of them, the cache-control headers work perfectly.

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

...

# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

...

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>

(ellipsis indicate superfluous ExpiresByType rule sections removed)

I've gone right through from my /etc/apache2/apache2.conf file through to pretty much every conf file included from there and can find no reasonable explanation. I've also fiddled, Pagesped and Chrome audited it to death for hours, and I'm still clueless.

Edit: As mentioned below, there is only one .htaccess file in the web root for this website. The JPEGs are coming through with the mime-type image/jpeg fine but the cache-control headers are missing and I can't figure out why.

like image 299
Marcel Avatar asked Mar 01 '11 04:03

Marcel


1 Answers

I added no-transform to the mod_headers section and sure enough, it all works as expected. Now I can give the wall a break from my forehead.

  <IfModule mod_headers.c>
    Header append Cache-Control "public, no-transform"
  </IfModule>
like image 177
Marcel Avatar answered Oct 20 '22 18:10

Marcel