I'm using Apache 2.2.16.

I've got the following HTML file in my htdocs folder:

 <link media="screen" type="text/css" href="/css/test.css" rel="stylesheet" />

I'm trying to make the CSS file cache in my browser so that it does not make another request for it, apart from on the first ever page load.

However, every time I press refresh, I can see that the CSS file is loaded again from the server. I see 200 response codes for the file in my server logs.

I've got the following in my httpd.conf file:

<LocationMatch "\.(css)$">
 Header set Cache-Control "max-age=2592000"
 Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT"
 Header unset Last-Modified
 Header set Content-Type text/css
 Header unset ETag

Here are my response headers, as reported by Firebug:

Date Mon, 29 Nov 2010 10:48:49 GMT
Server Apache/2.2.16 (Win32)
Accept-Ranges bytes
Content-Length 18107
Cache-Control max-age=2592000
Expires Thu, 15 Apr 2020 20:00:00 GMT
Content-Type text/css
Keep-Alive timeout=5, max=97
Connection Keep-Alive

I've read a few articles about setting the caching headers, but I just can't see to get it working.

Any advice greatly appreciated.

  • 1
    Are you doing a hard refresh? That will always cause the browser to download all of the files from the server regardless of what cache control is implemented. I'd try clicking some links to load the pages and see what results you get.
    – John Conde
    Commented Nov 29, 2010 at 14:14
  • D'oh... I'm monitoring the response codes in Chrome with developer tools, and in Firefox using Firebug. I'd disabled the browser cache in Firebug. I can't figure out if Chrome's developer tools disabled the broswer cache or not. However, when I disable the tools and inspect the traffic with Fiddler2, it seems like things are caching as expected! Thanks.
    – A_M
    Commented Nov 29, 2010 at 14:41
  • You aren't supposed to send more than one caching directive. Keep the max-age and ditch the Expires.
    – Zdenek
    Commented Dec 28, 2018 at 21:28

1 Answer 1


I use the following:

ExpiresActive on
ExpiresDefault "access plus 24 hours"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType text/css "access plus 1 months"
ExpiresByType text/javascript "access plus 1 months"
ExpiresByType application/javascript "access plus 1 months"
ExpiresByType application/x-shockwave-flash "access plus 24 hours"

It's quite easier to maintain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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