Home / Blog / SEO meta & schema

HTTP caching

HTTP ETag: Conditional Requests and Cache Validation

Use HTTP ETags for conditional requests, distinguish strong and weak validators, and test caching behavior with a controlled response sequence.

Eta Tag

The HTTP header is spelled ETag, short for an entity tag. It identifies a particular representation of a resource for conditional requests. It is not an HTML meta tag, a page title or an estimated arrival time. A server chooses the tag value; clients should treat it as an opaque quoted validator rather than infer how it was generated.

Read a tag from a real response

Use an endpoint you control for the following checks. Save the response headers, inspect its ETag, then make a second request that sends that same value back. The fictional tag below is an example: replace it with the actual tag your server returned.

curl --dump-header first-headers.txt --output first-body.txt https://example.com/resource
curl --dump-header second-headers.txt --output second-body.txt \
  --header 'If-None-Match: "revision-7"' https://example.com/resource

When the current representation matches the supplied validator, a conditional GET can receive 304 Not Modified. That response does not contain a fresh representation body; the client reuses the body it already cached. If the representation changed, expect the new body with a new validator on an ordinary successful response. A client with no cached body cannot reconstruct the resource from the tag alone.

A controlled verification sequence

  1. Serve a file containing revision one and make an initial request. Record status, ETag, Cache-Control, Content-Encoding and body bytes together.
  2. Request the same representation with If-None-Match containing the complete quoted tag. Confirm the response status and whether a body was sent.
  3. Change the source content to revision two. Repeat the old conditional request and check that the new representation is returned rather than a stale 304.
  4. Request through any production proxy or CDN as well as directly from the origin. Compare the representation and validator behavior at each layer.

This sequence detects a server that keeps a constant tag despite changing content. It also catches a test that accidentally requests a different URL, language or encoding variant on its second step. A tag only has meaning in the context of the selected resource representation.

Strong and weak validators

A weak tag has the prefix W/, such as W/"revision-7". Weak and strong validators have different comparison rules. Do not strip the prefix or quotation marks when copying a header. A weak validator can be useful for cache revalidation, while operations that require strong comparison cannot treat it as proof of byte-for-byte identity.

For an update workflow, a client may send If-Match with the validator of the version it edited. A server implementing that condition can reject an outdated update with 412 Precondition Failed, preventing a later editor from silently overwriting a newer version. This behavior must be implemented on the server; adding the header in a browser tool does not create conflict detection by itself.

ETag and Cache-Control solve different questions

Cache-Control determines reuse and freshness policy. ETag helps validate whether a stored representation is still current. A response may have both. Do not interpret an ETag as an instruction to cache sensitive content publicly, or assume that its presence overrides no-store. Headers added by a CDN can differ from origin headers, so inspect the final response that users actually receive.

Browser JavaScript may be unable to read a cross-origin ETag unless the response exposes it through the appropriate CORS response header. A header visible in developer tools but absent from a fetch Headers object can therefore be an exposure issue rather than proof that the server omitted it.

Avoid misleading tests

A HEAD request can help inspect metadata, but use a GET-based sequence when confirming cached body behavior. Preserve the same request variants, avoid adding a fresh cache-busting query on the second request, and record redirects. Never treat a status line from an earlier redirect as the final resource’s response. A header parser can organize pasted headers; it cannot prove how a server will answer the next request.

References

ETag, If-Match, and 304 Not Modified.