Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess: How to "Specify a cache validator"?

Tags:

I'm running Google PageSpeed on my site and it's tell me that I need to
"Specify a cache validator."

The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources:

... then it lists images, CSS, JS, etc.

According to http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching:

Set the Last-Modified date to the last time the resource was changed. If the Last-Modified date is sufficiently far enough in the past, chances are the browser won't refetch it.

I have the following in my .htaccess:

<IfModule mod_headers.c>     <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">         Header set Last-Modified "Tue, 31 Aug 2010 00:00:00 GMT"     </FilesMatch> </IfModule> 

What am I doing wrong?

like image 865
StackOverflowNewbie Avatar asked Sep 04 '10 09:09

StackOverflowNewbie


People also ask

What is a cache validator?

What is a cache validator? # A cache validator is defined within HTTP request and response headers and help determine if it is still valid to retrieve a file from the browser's cache.


1 Answers

I think the problem you are having is with Expire: and not with Last-Modified:. Apache would by default send the file Last-Modified: header based on the file date. I suggest removing the upper code and replacing it with the following:

<IfModule mod_expires.c>     ExpiresActive On     ExpiresDefault "access plus 1 year" </IfModule> 

Try with that, if it didn't work try adding this as well:

<IfModule mod_headers.c>     <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">         Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"     </FilesMatch> </IfModule> 
like image 68
aularon Avatar answered Oct 12 '22 14:10

aularon