← Lessons

quiz vs the machine

Silver1100

Networking

ETags and Conditional Requests

How a client revalidates a cached resource without re-downloading it.

4 min read · intro · beat Silver to climb

The revalidation problem

When a cached response goes stale, the client must check whether the resource actually changed. Downloading the whole body just to discover it is identical wastes bandwidth. Conditional requests solve this by letting the server answer not modified when nothing changed.

ETags and validators

An ETag is an opaque token the server attaches to a response that identifies a specific version of a resource. On the next request the client sends it back in an If-None-Match header.

  • If the current ETag matches, the server replies 304 Not Modified with no body.
  • If it differs, the server returns the full new response and a fresh ETag.
  • Last-Modified plus If-Modified-Since offers a weaker, timestamp based alternative.

ETags can be strong or weak. A strong validator means the bytes are byte for byte identical, while a weak validator only promises the representations are semantically equivalent. Weak tags are marked with a leading W slash prefix.

Key idea

An ETag identifies a resource version so a conditional request can return a tiny 304 Not Modified instead of resending unchanged data.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a 304 Not Modified response contain?

2. Which header carries an ETag back to the server for validation?

3. What does a weak ETag promise?