5

I have few warnings wich I'm tyring to solve in the pagespeed test, such as:

Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

And then it points out to local .js and .css files

But I have this in my htaccess:

<FilesMatch "\.(js|css|ttf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(html|htm|php)$">
    Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(css|js|gif|jpeg|png|ico)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FilesMatch>

Any idea what i'm doing wrong?

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

1 Answers1

0

Well, this is a shot in the dark but I came across circumstances where Apache would not respect my .htaccess headers and I had to "force" them with the always keyword like this:

<FilesMatch "\.(js|css|ttf)$">
    Header always set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header always set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(html|htm|php)$">
    Header always set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(css|js|gif|jpeg|png|ico)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
</FilesMatch>

When your action is a function of an existing header, you may need to specify a condition of always, depending on which internal table the original header was set in. The table that corresponds to always is used for locally generated error responses as well as successful responses. Note also that repeating this directive with both conditions makes sense in some scenarios because always is not a superset of onsuccess with respect to existing headers:

  • You're adding a header to a locally generated non-success (non-2xx) response, such as a redirect, in which case only the table corresponding to always is used in the ultimate response.
  • You're modifying or removing a header generated by a CGI script, in which case the CGI scripts are in the table corresponding to always and not in the default table.
  • You're modifying or removing a header generated by some piece of the server but that header is not being found by the default onsuccess condition.

From Apache Module mod_headers

spenibus
  • 4,339
  • 11
  • 26
  • 35