← Lessons

quiz vs the machine

Gold1420

Networking

Conditional Requests and Caching Validators

Revalidating cached content without resending the whole body.

5 min read · core · beat Gold to climb

Asking Only If Changed

A conditional request lets a client say send this only if it has changed. This revalidates a cached copy cheaply, avoiding a full transfer when nothing is new.

The Two Validators

A server attaches a validator to a response so the client can refer to that exact version later.

  • An ETag is an opaque tag, often a hash, identifying a specific representation.
  • A Last Modified date marks when the resource last changed.

The Conditional Headers

The client echoes a validator back on the next request.

  • If None Match sends the stored ETag.
  • If Modified Since sends the stored date.

If the resource is unchanged the server replies 304 Not Modified with no body, and the client reuses its cached copy. Otherwise it returns 200 with fresh content.

Strong vs Weak

ETags can be strong, meaning byte for byte identical, or weak, meaning semantically equivalent. Strong tags are required for partial range requests.

Key idea

Conditional requests use ETag or Last Modified validators with If None Match or If Modified Since, letting a server answer 304 Not Modified so an unchanged cached copy is reused without resending the body.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a 304 Not Modified response tell the client?

2. Which header carries a stored ETag back to the server?

3. Which validator is required for partial range requests?