What Is the Difference Between ETag and Last-Modified Headers?
Last-Modified is a timestamp-based cache validator with 1-second resolution, while ETag is an arbitrary content-based fingerprint (such as a hash) that accurately detects byte-level changes even when modifications occur multiple times in the same second or across distributed server clusters.
Detailed Technical Explanation
Both `Last-Modified` and `ETag` allow browsers to perform conditional HTTP requests (`304 Not Modified`) to save bandwidth. However, `Last-Modified` relies on the HTTP-date format (e.g. `Sun, 06 Nov 1994 08:49:37 GMT`), which cannot track sub-second modifications and is vulnerable to clock desynchronization across multi-server environments. An `ETag` (Entity Tag) is an opaque token, typically a SHA-256 hash or version string. When a resource changes, the server generates a new ETag. If both headers are present, RFC 9110 specifies that `If-None-Match` (ETag) takes precedence over `If-Modified-Since`.
Technical Example & Code
Showing how the browser sends conditional validators to receive 304 Not Modified.
// 1. Initial 200 OK Response from Server:
HTTP/1.1 200 OK
Last-Modified: Mon, 05 Oct 2026 12:00:00 GMT
ETag: "686897696a7c76"
Cache-Control: public, max-age=3600
// 2. Subsequent Conditional Request from Browser:
GET /styles.css HTTP/1.1
Host: example.com
If-Modified-Since: Mon, 05 Oct 2026 12:00:00 GMT
If-None-Match: "686897696a7c76"
// 3. Server confirms representation is identical:
HTTP/1.1 304 Not Modified
ETag: "686897696a7c76"
// (0 payload bytes transferred over the network!)Why This Is the Case (Underlying Architectural Rationale)
"Server clocks often drift by milliseconds, and build pipelines frequently deploy static assets that produce updated file timestamps without any actual changes to the underlying source code. By using a content-hash ETag, the server avoids invalidating client caches for harmless timestamp updates while immediately catching real byte modifications."
Common Misconception vs Reality
"Last-Modified is faster and better for CDNs than ETag."
ETag is significantly more reliable than Last-Modified in modern cloud environments because distributed server nodes often have slight timestamp discrepancies that cause false cache misses with Last-Modified.
Related Curious-Techie Resources
Complete Guide to HTTP Headers & Caching →
Master Cache-Control directives, stale-while-revalidate, ETag validators, and conditional requests.
Interactive ToolHTTP Header Analyzer →
Audit live cache headers, ETag formats, and conditional revalidation efficiency.
Developer ReferenceHTTP Caching Reference & Directives →
Related Questions in the Q&A Knowledge Base
An HTTP method is idempotent if executing it multiple times produces the exact same server state as executing it once. PUT is idempotent because repeating a PUT replaces the target resource at a known URI, whereas repeating a POST creates additional new subordinate resources or appends duplicate records each time.
HTTP/2 multiplexes requests by splitting HTTP messages into independent binary frames tagged with a unique Stream ID. These frames are interleaved concurrently over a single shared TCP socket, eliminating the head-of-line blocking problem of HTTP/1.1.
HTTP 401 Unauthorized means the user is not authenticated (identity unknown; credentials missing or invalid), whereas HTTP 403 Forbidden means the user is authenticated (identity known), but lacks the necessary permissions to access the requested resource.
関連技術エコシステムと次の学習ステップ
関連技術解説記事
What Is HTTP (Hypertext Transfer Protocol)?
Foundational stateless request-response protocol of the World Wide Web.
HTTP/1.1 vs HTTP/2: Multiplexing & Performance
Head-of-line blocking compared to binary framing and stream multiplexing.
Troubleshooting: HTTP 403 Forbidden Error
Diagnose server authorization denial, WAF IP blocks, and permission issues.
実践ハンズオン診断ラボ
開発者向け規格・仕様リファレンス
次のステップへ進む
HTTP Protocol & Header Inspection Lab
Craft raw HTTP headers and observe conditional 304 responses in the interactive workbench.