HTTP heuristic caching (missing cache-control and expires headers) explained

Click for: original source

Paul Calvano explains why WebPageTest can sometimes show that a repeat view loaded with less bytes downloaded, while also triggering warnings related to browser caching. It can seem like the test is reporting an issue that does not exist, but in fact it’s often a sign of a more serious issue that should be investigated.

Article touches on the fundamentals of HTTP caching. HTTP client to cache a resource it needs to understand:

  • RFC 7234 specifically section 4.2 (Freshness) and 4.3 (Validation), e.g.:
  • How long am I allowed to cache this for?
  • How do I validate that the content is still fresh?

The HTTP Response headers typically used for conveying freshness lifetime:

  • Cache-Control (max-age provides a cache lifetime duration)
  • Expires (provides an expiration date, Cache-Control max-age takes priority if both are present)

The HTTP response headers for validating the responses stored within the cache:

  • Last-Modified (contains the date-time since the object was last modified)
  • Etag (provides a unique identifier for the content)

When both are present in a response, the browser will prioritize the Cache-Control over the Expires header. And much more detailed information in the article. Well worth your time!

[Read More]

Tags programming web-development