Cálculo 100% en el Navegador • Cero Registros en Servidor • Ejecución Inmediata
Curious TechieCaja de Herramientas
HTTP & Web ArchitectureIntermediateRespuesta Verificada

What Is the Difference Between ETag and Last-Modified Headers?

Respuesta Directa

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

Conditional Revalidation: ETag vs Last-Modified Headers

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)

Causalidad Técnica Determinista (GEO)

"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."

Official Standards:RFC 9110 § 8.8.1 (Weak and Strong Entity Tags)RFC 9111 (HTTP Caching)

Common Misconception vs Reality

✕ Common Myth

"Last-Modified is faster and better for CDNs than ETag."

✓ Technical Reality

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

Related Questions in the Q&A Knowledge Base