views:

17

answers:

1

I'm tyring to implement browser caching and follow Google PageSpeed's recommendation about setting Last-Modified to a data that is "sufficiently far enough in the past." I have the following in my .htaccess:

<IfModule mod_headers.c>
 <FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
  Header Set Last-Modified "Fri, 01 Jan 2010 12:00:00 GMT"
 </FilesMatch>
</IfModule>

I have mod_headers installed on my server.

Unfortunately, Google PageSpeed still complains and warns me:

Leverage browser caching

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

And then lists PNGs, GIFs, JPGs, etc. Yahoo YSlow says basically the same thing.

Looking at the response headers of one of my resources that should be caching, I see this:

Date:           Tue, 19 Oct 2010 20:12:04 GMT
Server:         Apache/2.2.14 (Ubuntu)
Last-Modified:  Tue, 07 Sep 2010 23:51:33 GMT
Etag:           "2e0e34-2a43-48fb413a96a20"
Accept-Ranges:  bytes
Content-Length: 10819
Content-Type:   image/png

As you can see, the Last-Modified data does not match what I specified in .htaccess.

Any ideas what I am doing wrong?

A: 

Have you considered just using unset Last-Modified?

Example:

<IfModule mod_headers.c>
 <FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
  Header unset Last-Modified
 </FilesMatch>
</IfModule>

The FilesMatch section looks fine, so it's probably just some fiddly bit with Header Set. Hell, might even be case sensitive. Try Header set instead of Header Set

If this isn't what you want, then let me know and I'll think about it a bit more. Unset should work though,

warandpeace
I tried `Header set`; it did nothing. Then I tried `Header unset Last-Modified`; that also did nothing. My .htaccess seems to ignore header directives, but respects compression (DEFLATE) directives. Any more ideas?
StackOverflowNewbie
Actually, I just commented out my compression directives. However, the resources are still being served as compressed. Now, I think I am more lost than when I started.
StackOverflowNewbie
If you're comfortable doing it, would you mind editing your original post to include the whole .htaccess file? I'd like to look at the whole thing, if I could.
warandpeace
Never mind. Turns out, something in the server was preventing it. Admin fixed it. Thanks.
StackOverflowNewbie