ETag

Caching

Overview

An ETag (Entity Tag) is an opaque identifier for a specific version of a resource (usually a content hash) that the server sends in the response header.

When the client re-requests and returns this value as a conditional header, the server replies with just `304 Not Modified` and no body if the content is unchanged, saving bandwidth.

Details

How it works: the first response carries `ETag: "abc123"`, and later the browser sends a revalidation request with `If-None-Match: "abc123"`. If unchanged, the server returns `304` (no body); if changed, it returns `200` with a new body and new ETag. This is more precise than time-based `Last-Modified`/`If-Modified-Since`, correctly detecting sub-second changes or cases where timestamps differ but content is identical.

The distinction between strong and weak (`W/` prefix) ETags matters: a strong ETag guarantees byte-for-byte equality, while a weak ETag means 'semantically equivalent' (e.g. differing only in compression) and can't be used for Range requests. Note that `Cache-Control: max-age` means 'don't even ask while fresh,' whereas an ETag means 'revalidate after expiry' — the two are complementary. Also, if load-balanced servers generate different ETags for the same content, cache efficiency drops, so generation must be kept consistent.

Related types