EasyCaching Strategies📖 Theory Question

What is ETags and conditional requests, and when does the browser use them?

💡

Hint

ETag is a fingerprint the server sends; browser sends If-None-Match on revalidation — 304 Not Modified skips re-downloading the body

Full Answer

An ETag (Entity Tag) is an opaque identifier the server assigns to a specific version of a resource.

// Server response
HTTP/1.1 200 OK
ETag: "abc123"
Cache-Control: no-cache
Content-Type: text/html

Revalidation flow:

  1. Browser stores the response with its ETag.
  2. On next request (after cache expires or with no-cache), browser sends: If-None-Match: "abc123"
  3. If content unchanged → server responds 304 Not Modified with no body — saves bandwidth.
  4. If content changed → server responds 200 OK with new content and new ETag.

Last-Modified / If-Modified-Since — older alternative using a timestamp instead of a hash. Less reliable (timestamps can be off).

When browsers use conditional requests:

  • When Cache-Control: no-cache is set (revalidate every time).
  • When max-age has expired.
  • When the user does a soft reload (F5 on Windows).

More Caching Strategies Questions

EasyWhat is the Cache-Control header and what are its key directives?EasyWhat is stale-while-revalidate and why is it a good default for HTML pages?EasyWhat is content-based cache busting and how does it work?EasyWhat caching strategies can a service worker implement?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint