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.
Firefox has cached your object and is revalidating the object with the origin server. You can tell this because it sent the
Cache-Control: request headers.
Firefox will generally revalidate cached objects in two situations:
- The cached object is stale, as determined by the
Expires:response headers that were sent with the object when it was previously cached.
- 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.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.