Overview
An ETag (Entity Tag) is a string (often a hash of the file content) that represents a specific version of a resource. It allows the browser to perform 'conditional requests' to see if a cached resource is still valid.
How it Works
- Initial Request: Server sends the resource with an
ETagheader. - Subsequent Request: Browser sends the ETag back in the
If-None-Matchheader. - Validation: If the ETag matches, the server returns a
304 Not Modifiedstatus, and the browser uses the cached version. If it doesn't match, the server sends the new version.
Benefits
ETags prevent unnecessary data transfer when a resource hasn't changed, even if its max-age has expired.