Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm using Apache 2.2.16.

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

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

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
</LocationMatch>

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.

share|improve this question
    
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 Nov 29 '10 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 Nov 29 '10 at 14:41
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

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.