COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
53/ 70

Caching and conditional requests

ETag, Last-Modified and 304

Avoid downloading unchanged bodies.

UnderstandStudy an examplePractise

Understand the concept

An ETag is an opaque representation validator, not necessarily a hash or database version. If-None-Match checks it. An unchanged GET/HEAD can return a bodyless 304 with cache metadata, allowing reuse of a stored representation.

Last-Modified uses time-based validation with precision and clock limitations. Condition precedence matters when validators coexist. Weak ETags describe semantic equivalence, not the same guarantee as strong byte equality.

Compression and language variants affect validator design. Do not assign one validator to incompatible bodies. A 304 is not an empty successful JSON document. Browser cache views may combine a network validation response with stored content.

WHEN TO USE IT

Reduce transfer while maintaining freshness.

COMMON PITFALL

Parsing a 304 response as JSON.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
HTTP/1.1 200 OK
ETag: "v1"
Cache-Control: max-age=0

The first response supplies a validator.

This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.

02 / YOUR TURN

Try it yourself first.

Does 304 carry a new article body?

Show the solution and explanation
Worked solution
304 → reuse stored representation

No; an appropriate stored representation is needed.