Course contentsShow
← Cloud and Infrastructure
Lesson 2674 of 2,98958. Caching StrategiesFree lesson

ETag and Conditional Requests

Learn how ETags enable validation-based caching and reduce bandwidth with 304 Not Modified responses.

ETag and Conditional Requests

What you'll learn: How ETags enable browsers and CDNs to validate cached content efficiently, reducing bandwidth without sacrificing freshness.

What is an ETag?

An ETag (Entity Tag) is a unique identifier—typically a hash or version string—that represents a specific version of a resource. When a server sends a file, it includes an ETag header like "abc123". Think of it like a fingerprint: if the content changes, so does the fingerprint.

The client stores this ETag along with the cached copy. When it needs to revalidate, it sends the ETag back to the server using an If-None-Match header. The server compares:

  • If the ETag matches (content unchanged): The server responds with 304 Not Modified and no body—saving bandwidth dramatically.
  • If the ETag differs (content changed): The server sends 200 OK with the new content and updated ETag.

How Conditional Requests Work

  1. Initial request: Server responds with ETag: "v1" and full content.
  2. Cache expires or needs validation: Client sends If-None-Match: "v1".
  3. Server validates: Checks if current resource still has ETag "v1".
  4. 304 response: Just headers, no body transfer (saves kilobytes or megabytes).

This is especially powerful combined with Cache-Control: must-revalidate or short max-age values—you guarantee freshness while minimizing data transfer.

ETag vs Last-Modified

ETags complement Last-Modified/If-Modified-Since headers but work better for:

  • Content-based changes (not just timestamp changes)
  • Resources generated dynamically (same timestamp, different output)
  • Sub-second precision needs

Key Takeaway: ETags provide validation-based caching, allowing servers to confirm content hasn't changed with tiny 304 Not Modified responses instead of retransmitting entire files—crucial for bandwidth optimization at scale.