DEV Community

Cover image for Understanding Cache-Control and ETag for efficient web caching
Andreas Bergström
Andreas Bergström

Posted on • Edited on • Originally published at andreasbergstrom.dev

Understanding Cache-Control and ETag for efficient web caching

Cache-Control and ETag solve different halves of the same problem and are at their best together: Cache-Control says how long the client can skip the server entirely (max-age, no-cache, public/private, must-revalidate); ETag is the freshness check used when the cache does want to ask — the client sends If-None-Match, the server replies 304 Not Modified if the tag matches and saves the bytes.

The full post walks through the directives, what If-None-Match looks like on the wire, and why ETag-only is worse than the pair (more round trips, no public/private split, no immutable on versioned assets).


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (1)

Collapse
 
didof profile image
Francesco Di Donato

Very well explained and straight to the point. Bravo!