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 have a client whose site's index.html currently comes back with these headers:

Accept-Ranges:    bytes
Connection:       Keep-Alive
Content-Encoding: gzip
Content-Length:   3658
Content-Type:     text/html
Date:             Thu, 10 Oct 2013 07:36:27 GMT
ETag:             "4aa95e1-2ed2-4e721324728b7"
Keep-Alive:       timeout=5, max=100
Last-Modified:    Tue, 24 Sep 2013 13:34:30 GMT
Server:           Apache/2.2.22
Vary:             Accept-Encoding,User-Agent

I'm obviously going to recommend that they add Expires or Cache-Control as appropriate, but I'm confused: Chrome caches this resource and uses it from cache (not sending a request at all), even after several hours (for instance, it reused a copy it cached yesterday at 1:30 p.m. this morning at 8:30 a.m.). I can see this quite clearly in the Chrome console's Network tab, where it shows the request and has 200 (OK) in grey in the Status column and (from cache) in the Size column. (I haven't changed Chrome's caching defaults.)

I realize that the spec allows user agents to make their own decision in the absense of direction from the headers. Is that what's happening here? Chrome sees it was last modified several days ago and feels free to use a version that's (say) up to a day out of date? Or is there something I'm missing?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

When "Expires" and "Cache-Control" headers are not specified, but a "Last-Modified" header is specified, browsers have to guess at how long they should keep the document in cache. Some browsers do use algorithms that let the page remain in cache for a day or more.

Google caching best practices guide states:

Last-Modified is a "weak" caching header in that the browser applies a heuristic to determine whether to fetch the item from cache or not. (The heuristics are different among different browsers.)


Mozilla (Firefox) has an HTTP Caching FAQ that outlines their algorithm for this situation (although it is possible that the algorithm has changed since the document is dated 2002):

...we look for a "Last-Modified" header. If this header is present, then the cache's freshness lifetime is equal to the value of the "Date" header minus the value of the "Last-modified" header divided by 10.

So in your case where the difference between modified and now is 15 days, then Firefox would cache the resource for 1.5 days.


I was unable to find references for the specific heuristics used by other browsers such as Chrome, Safari, and Internet Explorer. A question has been asked on StackOveflow asking for these heuristics, but it has only received the Mozilla answer.


The size of the browser's cache will probably be the limiting factor for a file that the caching algorithm determines may be kept for more than a day. Browsers generally have a setting for the amount of disk space they use for cache. Many users also clear their cache when they close their browser. So the amount of time for which such a file is cached usually depends on:

  • The amount of cache space the browser has allocated
  • The number of websites that a user visits (and the size of those sites)
  • Whether or not the user has closed their browser
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.