Cache-Control and ETag: How HTTP Caching Headers Divide Their Responsibilities
Cache-Control and ETag are two HTTP response headers that together manage browser and CDN caching, but each answers a different question. Cache-Control defines how long a cached response stays fresh without contacting the server, using directives like max-age, public, and immutable. ETag acts as a content fingerprint — typically a hash — that allows browsers to cheaply verify whether a resource has changed once the Cache-Control window expires. When a cached copy expires, the browser sends the stored ETag value in an If-None-Match request header; if the content is unchanged, the server replies with a lightweight 304 Not Modified response instead of retransmitting the full file. A practical example from an open-source OGP image generator illustrates how combining a 30-day max-age with the immutable directive eliminates revalidation requests entirely, provided the URL reliably points to unchanging content.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in