I do understand how Cache-Control header works. However, I noticed that the browser treats the document request differently from other requests. The document request here is the first request that the browser makes when the user types the domain on the address bar and hits enter.
I tested an HTML page with the response header as follows:
Cache-Control: public, max-age=31536000, immutable
The header tells that the browser should cache the response for 1 year. But in the case document request, both Chrome and Firefox will revalidate it anyway. The evidence for it is the 304 response status.
Here is the test URL: https://test-http-cache-2exijs7pxj7x.runkit.sh/
I can not find an official document for this behavior. So it would be nice if someone could explain how the browser caches the document request and refers to an official document.
Thanks in advance!
Edit
The outcome mentioned above is the result of a soft reload (when the user hits the reload button or re-enters the same address). For navigation requests, the browser respects the Cache-Control and serves the response from the cache

According to the spec, the
immutableextension to theCache-Controlheader:The freshness of a response is determined by its age, which in HTTP is the time elapsed since the response was generated. You can read more about how a cache calculates the age on MDN, but it is essentially the difference between when the object was stored by the cache and it's
max-age(or the value of anExpiresheader), which in your case is one year, so any cache following the spec, should not attempt a conditional request to validate the stored object.I have confirmed on my Ubuntu laptop using Chrome and Firefox that Firefox will not issue a conditional validation request upon caching the response, but Chrome will. If you inspect the Browser compatibility table on MDN for the
Cache-Controlheader, you will see that Chrome does not support theimmutableextension, but Firefox does.In short, according to the spec, clients should not issue a conditional request to validate a cached object that included the
immutableextension to a response'sCache-Controlheader while the object is still fresh.Chrome is not honoring the
immutableextension, and therefore issuing a conditional request in the form of anIf-None-Matchrequest header due to theEtagon the returned resource.Addendum:
The comments to this answer add an additional question not readily apparent in the original question. Namely, why is Chrome validating a cached resource that is fresh when a user reloads the page, but not during navigation?
Chrome has decided to not support
immutablebecause they seem to feel their heuristic at handling reloads is sufficient and not worth the overhead of supporting another extension toCache-Controlwith little observed value. It has been available to work on for years, but nobody has bothered.In short, their heuristic will only validate a cached top level resource on reloads (which real end users really don't do), and use the cache for sub-resources. You can read about how Chrome revamped their heuristic in this article: https://blog.chromium.org/2017/01/reload-reloaded-faster-and-leaner-page_26.html
Note, the test URL provided in the question does not have any sub-resouces. Not only that, it appears to be serving plain text as
text/htmlwheretext/plainmight be more appropriate.