Forum Moderators: phranque

Message Too Old, No Replies

Caching/Expires headers

being ignored by browser?

         

harold2

12:35 am on Jun 9, 2008 (gmt 0)

10+ Year Member



I'm working on a site which uses some fairly heavy .js files; I'd like to encourage browsers to cache this.

I've enabled mod_expire and - just for test purposes - added this to my vhost config, inside the <Directory></Directory> directives:

ExpiresDefault "access 6 months"

It seems to be working. If I request a .js file in my browser and look at the headers sent back:

Cache-control:max-age=1555200
Expires: Sat 06 Dec 2008 00:29:51 GMT

, but if I refresh the page and look at my Apache access_log, I see my browser issuing another GET request for the .js file. So clearly it isn't being cached.

I've tried this in Firefox and Konqueror. In the former, I double checked by browser settings (caching enabled, increase the size of the disk cache).

Am I missing something stupid here? Is it a case that cache-control/expires are only used by intermediate web proxies like squid, and not by browsers? I realise that I can't force a browser to cache content, but it seems strange that FF isn't caching despite my encouragement

cabowabo

1:47 am on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the version of Apache? If you are below 2.x, that is the cause.

harold2

8:49 am on Jun 9, 2008 (gmt 0)

10+ Year Member



It's 2.2.3

cabowabo

10:56 am on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this code to see if it works to help you narrow down the issue.

<FilesMatch "(jpg¦jpeg¦gif¦js¦css)">
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

jdMorgan

10:02 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When your browser issues that second request, what is the server's response -- a 200-OK, or a 304-Not Modified?

Also, look to make sure that there are not multiple cache-control headers, one with a "no-store" and/or "must-revalidate" directive.

A very good tool for this kind of testing is the "Live HTTP Headers" add-on for Firefox/Mozilla browsers.

Jim