I'm looking for a best possible caching/expires configuration for my specific situation.

I realize that some sites have advocated turning etags off: Header unset ETag, FileETag None

I know that I should use either Expires or Cache-Control. In additions, I know that I should use either Last-modified or ETAGs (Per ySlow docs).

I inherited a clients server that uses the following in .htaccess:

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|xml|txt|html|htm)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"

With this server I am not going to be able to rely on staff to rename images, css and js in web applications so I do not want to set the expires far in the future without knowing (with a good certainty) that "most/all" browsers will check to see if content has changed. What I do not want to happen is someone call me and say the website is broken because they replaced an image and it's not showing up.

But I do want to take the most advantage I can with caching and expires while still maintaining that mostly all browsers will check with the server to see if components have changed.

I have access to both the .htaccess and apache .conf file and it is a single server, the content is not deployed on multiple servers.

What would be the best .htaccess or .conf configuration for me to achieve my goals for this clients server?

Thanks for your help

  • Why did you disable ETags? – mgorven Jun 8 '12 at 0:27
  • I didn't turn off etags. What I want is to set a far in the future expires but still have the user check to see if the file has been changed/modified (probably via etags). Any suggestions on the config I should use? – mcondiff Jun 8 '12 at 14:31

You should have eTag turned on although some people have recommended against it when using load balancers.

For expiring and cahcing yoru content, you can either use mod_expires and configure which resources and their age . Or you can set this this httpd.conf

Header set Cache-Control "max-age=63072000, public"

Now when you see your response headers, you would see Cache-Control with an age. I have set it for 2 years

> Cache-Control:max-age=63072000, public Connection:close Date:Thu, 22
> Oct 2015 17:09:31 GMT ETag:"2b7e6-a9777-523307081ff00"
> Server:Apache/2.2.3  Vary:Accept-Encoding,User-Agent

Basically, make sure that the server sends Etag and Last-Modified headers (which allows clients to check whether a resource has changed without actually downloading it), and set Expires and Cache-Control: max-age headers as far in the future as you can. If static content is going to be changed without being renamed, then the best you can do is set it such that it covers a typical browsing session (e.g. 15min).

  • I've read that you either send etags OR set last modified. But could you come up with something i can put into my .htaccess that would correspond with your answer? – mcondiff Jun 12 '12 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.