Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a problem with JS and CSS files being cached for far too long by the browser. We do frequent development, and whenever we push out a change it breaks for some users who have the old version cached. But I can't figure out why our server is caching so hard.

I looked in our httpd.conf and we have this:

<IfModule mod_headers>
   <FilesMatch "\.(css|js)$">
     Header set Cache-Control "max-age=43200, public, must-revalidate"

So, if I'm understanding this right, it should be setting JS and CSS files to cache for 12 hours - and even then check the file w/ the server to see if it has changed. But when I inspect the HTTP Response headers I get, I don't even see any Cache-Control headers! But instead of never caching these files, the browser appears to be ALWAYS caching them.

No other headers are set in our conf, and as far as I can tell we aren't even using mod_expires. This is our own server, not some hosted solution, so I have complete control over the box. We don't use .htaccess files so it's not being overridden somewhere these...

I know I'm doing something wrong here. I am pretty sure I have mod_headers installed correctly in apache, but I'm not sure how to check. Should I be using mod_expires instead or in addition? Should I be using a different max-age?

Thanks for any help you guys can provide.

edit: After further experimentation, I've found that the headers do get sent if I comment out the <IfModule mod_headers> statement. This is confusing, because if the module wasn't there then the resulting Header set wouldn't work either. But sure enough it is working on my development server.

I'm nervous to deploy this as-is to our live server though. Any thoughts on why mod_headers would not be recognized by IfModule, yet still work?

share|improve this question
up vote 0 down vote accepted

First of all do you have mod_headers loaded?

If you remove the ifmodule directives and check for errors with

apache2ctl configtest

you will see for sure.

Another thing. I do not know you application, but you should consider instead of playing with the caching of these files upload new files. So you replace your.css with your-v1.css in your html content. (That is what I would do for production sites, what you want to do is ok for a development mode site.)

share|improve this answer
I have confirmed that the module is installed, or at least that the configtest comes back with "Syntax Ok". As for renaming files, that isn't a good solution for us. – DOOManiac Mar 13 '12 at 19:49
Found the culprit. It should be: <IfModule mod_headers.c>, not <IfModule mod_headers>. Thanks for pointing me in the right direction! – DOOManiac Mar 13 '12 at 21:14
You are welcome! – cstamas Mar 13 '12 at 21:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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