Course contentsShow
← Web Development
Lesson 2144 of 2,98239. Network PerformanceFree lesson

ETag and Validation

Using ETags for conditional requests and validation-based caching strategies.

ETag and Validation

You'll learn how ETags enable browsers to validate cached resources efficiently without re-downloading unchanged content.

What Are ETags?

An ETag (entity tag) is a unique identifier that servers attach to a resource, typically as a hash of its content. Think of it like a fingerprint for a file—when the file changes, so does its fingerprint.

When you first request a file, the server sends it along with an ETag header:

ETag: "5d8c72a5e0a0"

Your browser caches this file and remembers the ETag value.

How Validation Works

On the next request, instead of blindly downloading the file again, the browser sends a conditional request with the If-None-Match header containing the stored ETag:

If-None-Match: "5d8c72a5e0a0"

The server checks if the resource has changed:

  • If unchanged: Server responds with 304 Not Modified (no body content), saving bandwidth
  • If changed: Server sends 200 OK with the new file and updated ETag

The Validation-Based Caching Strategy

This creates a validation-based caching pattern: resources are stored locally, but the browser still "checks in" with the server. It's more bandwidth-efficient than full re-downloads but less efficient than aggressive caching with Cache-Control: max-age.

This strategy works best for resources that might change but you want to ensure freshness—like API responses, user-specific content, or frequently updated assets.

ETags vs Last-Modified

ETags work similarly to Last-Modified headers, but ETags are more precise (content-based) while Last-Modified is time-based and only accurate to the second.

Key Takeaway: ETags enable conditional requests where browsers validate cached content with the server, receiving lightweight 304 responses when nothing has changed—balancing freshness with performance.