Why does Firefox still make connections to server although the HTTP resources are shown as "cached"?

23r23f23q asked:

I am confused by the way Firefox shows loaded resources as cached but then I can see the browser issues new DNS query for the domain name and contact the HTTP server again.

Below is a simple example of this behavior. I visited https://example.com then reload the webpage. As expected, the loaded resources are shown as cached. But, at the same time, I run tcpdump in background and notice that the browser issues DNS query for example.com again and also connects to the HTTP server after getting the DNS response.

dd
Is this an expected behavior or am I missing something?
Thank you for reading my question <3

My answer:


Firefox has cached your object and is revalidating the object with the origin server. You can tell this because it sent the If-Modified-Since: and Cache-Control: request headers.

Firefox will generally revalidate cached objects in two situations:

  1. The cached object is stale, as determined by the Cache-Control: and Expires: response headers that were sent with the object when it was previously cached.
  2. You hit Reload.

You can see that the web server sent a 304 Not Modified response, and thus Firefox served the existing cached object.


HTTP caching can get quite complex. To learn all about it, spend an evening studying RFC 7234.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.