Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am developing a web application and I've set up my JavaScript and CSS files to have far future expires. I send back to the client that each file was last modified a year ago and that each file expires in a year. The problem is that Firefox and Chromium seem to ignore the response headers and refetch the static files every single time the page is reloaded.

Opera, on the other hand is operating as expected. That is to say, it caches the files with the far future expires.

I am using Ubuntu 10.04, Firefox 3.6.8 and Chromium 5.0.375.125. Are Firefox and Chromium configured to not cache files from localhost by default? Is there a way to change this setting? Anybody have ideas on what else might be causing them to not cache?

These are the response headers that I send back to the client:

Server    Development/1.0
Date    Tue, 31 Aug 2010 15:44:16 GMT
Content-Language    en
Expires    Wed, 31 Aug 2011 15:44:16 GMT
Vary    Accept-Language, Cookie
Last-Modified    Mon, 31 Aug 2009 15:44:16 GMT
Cache-Control    max-age=31536000
Content-Type    text/css
Content-Length    32493

Thanks!

share|improve this question
2  
Please don't crosspost: stackoverflow.com/questions/3610783/… –  Hello71 Aug 31 '10 at 15:52

1 Answer 1

up vote 0 down vote accepted

To answer your question, Chromium and Firefox, or any other browser for that matter, will cache files from localhost. The problem is that you're using a directive that is kept only for backward compatibility.

In other words, in the old days this was the way to go. By setting the expiration date in the distant past they would force a browser to not display a page from the cache. Probably Chromium and/or Firefox just ignores this directive.

On the other hand you have some other nice alternatives:

  • Cache Control: No-cache: will re-validate with the server before serving the page from the cache.
  • Cache Control: must-revalidate, browser should re-validate with the server before serving it from cache.
  • Cahce Control: no-store, don't cache and don't store the page in the cache folder

Remember that you are still at the mercy of the browser and each has it's own way (unfortunately) of dealing with these directives.

Source: Cache Control Directives Demystified

And you should also read this where it explains that the basic expiration mechanism has changed: when using both Expires and max-age, the max-age directive will override the Expire header.

Source: 14.9.3 Modifications of the Basic Expiration Mechanism

share|improve this answer
    
Thanks for the answer! –  J. Frankenstein Jul 22 '12 at 0:01

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.