Issue
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?
Solution
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,
Answered By - warandpeace Answer Checked By - Terry (WPSolving Volunteer)