Apache Caching and Expires configuration

apache-2.2cacheetagslast-modified

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"
</FilesMatch>

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

Best Answer

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