ETag
Definition
An ETag, short for entity tag, is an opaque string in a response header that identifies one particular version of one particular resource. It looks like ETag: "5f3a9c1b-2e40" and usually derives from a checksum of the contents, or from the file size and modification time. The client is not meant to interpret it — only to hand it back and see whether it still matches. There are two kinds: a strong ETag means byte-for-byte identical, while a weak one, written with a W/ prefix, means semantically equivalent. It works alongside Cache-Control rather than instead of it, since the header decides how long a copy is used without asking and the ETag decides what happens once that period ends.
Why It Matters
Revalidation is what keeps frequently checked files nearly free. A 304 response is a few hundred bytes of headers, against perhaps 300 KB for the image it refers to — a saving of over 99 percent on the wire for exactly the same outcome. On a page that sends no-cache on its markup, that is the difference between a 40 KB download on every navigation and a round trip that returns almost nothing. The failure mode is subtle rather than dramatic: if your value changes when the content has not, because two servers behind a load balancer compute it differently, every revalidation returns a full 200 with the whole body. The page still works, it is simply slower and more expensive than it should be, every time.
How It Works
The server sends ETag with the response and the client stores it with the cached copy. When that copy is stale, or when the response said no-cache, the client repeats the request with If-None-Match carrying the stored value. The server compares it against the current identifier: a match returns 304 Not Modified with headers only and a refreshed freshness lifetime, a mismatch returns 200 with the new body and a new ETag. If-Modified-Since with a Last-Modified date does the same job at one-second granularity and is the older, coarser mechanism; where both are present, If-None-Match wins. The same header underpins optimistic concurrency on writes, where If-Match rejects an update if the resource changed since you read it.
Real-World Example
A club keeps a fixtures page on 99helpers at bellwood-fc.99helpers.site and updates it most weeks. Members refreshing on a Saturday morning send If-None-Match with what they already hold; for as long as nothing has changed they get a 304 and the page renders from local storage in milliseconds. The week a result is posted, the identifier changes and the new markup is sent in full, once. Nobody at the club configured any of this, and the effect is that a page checked twenty times a week is downloaded roughly once.
Common Mistakes
- ✕Turning it off to fix a stale content problem — the identifier is what makes revalidation cheap, and disabling it means full downloads rather than fresh ones
- ✕Serving from several machines that compute the value differently — clients then get a mismatch on every request and never see a 304, no matter how unchanged the file is
- ✕Relying on it to push out a change immediately — a copy still inside its max-age is not revalidated at all, so nothing is asked and nothing arrives
- ✕Assuming it does the job of a content hash in the filename — revalidation still costs a round trip, while a new filename costs none
Related Terms
Cache-Control
The HTTP response header that tells browsers and caches whether they may keep a copy of a file, for how long, and who is allowed to. It is the single biggest lever over how fast a site feels on a second visit.
Cache Invalidation
Getting rid of cached copies of a file that is no longer correct, so visitors stop being served the old version. There are two ways to do it, and only one of them is reliable.
HTTP Status Code
An HTTP status code is the three-digit number a server returns at the head of every response, saying what happened to the request. It is the first thing on the first line — a 200 means here is the file, a 404 means there is nothing at that address.
Checksum
A checksum is a short fixed-length value calculated from a file's bytes, used to confirm that the copy you received is identical to the copy that was sent. Same bytes in, same value out — and one changed bit produces a completely different value.
File Versioning
File versioning keeps the previous copy of a file when a new one is uploaded under the same name, instead of overwriting it. Every publish adds to a history you can read back from, rather than replacing what was there.
Put a file online in seconds
Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.
Host a file free →