Conditional requests and validators
Avoid downloading an unchanged file
A validator is metadata that helps decide whether a saved representation is still valid. A client can send a conditional GET with its stored ETag or modification date. If the representation has not changed, a 304 response lets the client reuse its stored body. A 304 is not a replacement empty page.
HTTP/1.1 200 OKETag: "guide-v1"Last-Modified: Tue, 10 Nov 2026 10:00:00 GMTCache-Control: no-cacheGET /index.html HTTP/1.1Host: cache.testIf-None-Match: "guide-v1"
HTTP/1.1 304 Not ModifiedETag: "guide-v1"Cache-Control: no-cacheA client should combine the applicable 304 metadata with its stored response and reuse the stored body. If the current tag does not match, a normal GET can return 200 with a new body. These illustrative tags are not a prediction of the exact tag Nginx generates.
Date-based validation and Nginx controls
location = /index.html { etag on; if_modified_since exact; add_header Cache-Control "no-cache" always;}Nginx can generate ETags for static resources; disabling this feature does not automatically strip arbitrary upstream ETags. The exact date comparison is the documented default; before permits a modification time no later than the supplied date. HTTP defines If-None-Match as taking precedence over If-Modified-Since when both are present. For the lab test each validator separately. Date resolution and deployment metadata can cause collisions; a static ETag is not guaranteed to be a cryptographic digest. Publish content-hashed filenames for immutable files and ensure changed HTML has distinguishable metadata.
Try a real validator in an approved lab
curl -sS -D - -o /dev/null http://127.0.0.1:8080/index.html# Replace the sample tag with the exact returned value.curl -sS -D - -o /dev/null -H 'If-None-Match: "sample-tag"' http://127.0.0.1:8080/index.htmlAn actual matching tag should produce 304 for the unchanged static file. A nonmatching tag should produce 200. HEAD is useful for inspecting metadata but the lab uses GET to test body reuse semantics. curl by itself does not act like a persistent browser HTTP cache; these requests are explicit.
Variants and common mistakes
Vary tells caches which request headers distinguish representations, for example Accept-Language if the origin really serves different languages. Vary is not an authorization control. Weak ETags (prefixed W/) can validate semantic equivalence for GET; strong validators are needed for some byte-range operations. Do not fabricate tags by hashing an unrelated URL. Practice predicting the response before and after a changed HTML file. Next: response header policy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Conditional requests and validators
Use ETag and Last-Modified to understand conditional GET, 304 responses and safe asset updates.
What does a 304 response mean for a cached GET?
Which request field carries a saved ETag?
A current ETag differs from the only tag in If-None-Match. What is expected for an otherwise successful GET?
Why is a date validator sometimes insufficient?
Origin serves language variants. What can Vary: Accept-Language communicate?