What is an ETag in HTTP?

A web server assigns an ETag, or entity tag, to a specific version of a resource located at a URL. It is a component of HTTP (Hypertext Transfer Protocol), which is used to validate web caches and allows clients to make conditional requests. If the content of the resource at that URL changes, a new ETag is assigned. ETags are similar to fingerprints in that they may be compared rapidly to see if two versions of a resource are identical.

How an ETag works

  • The client (browser or HTTP client) sends a git or POST request to the web server for a specific resource.
  • The server responds with the status code 200 and an ETag header.
  • If a client requests the same resource from the server with the conditional request header If-None-Match, the server compares the ETag value in the request header with the ETag identifier on its side.
  • If both ETags are the same, the client receives a status code of 304 (Not Modified) with an empty body, signaling the application to use the cached copy of that specific resource.
  • If the ETags are not the same, the resource’s content has been modified, and the web server will deliver a new version of the resource with a new ETag and a status code of 200.
  • The application will then update its cache and use the new resource version.
How an ETag works

ETag value generation

The three ways to generate ETags are as follows:

  • A revision number: An ETag can be generated using a revision number, which is a version number or a timestamp associated with the resource.
  • A collision-free hash function of the Resource’s content: An ETag can also be generated using a collision-free hash function of the resource’s content, which is a mathematical algorithm that generates a unique identifier for the resource’s data.
  • Hash function of last modification timestamp hash: An ETag can be generated using a hash function of the last modification timestamp of the resource, which generates a unique identifier based on the time the resource was last modified.

ETag value validation

In HTTP, ETag value validation is a process used to determine if a client’s cached version of a resource is still valid. The validation process involves comparing the ETag value of the client’s cached version of the resource with the ETag value of the current version of the resource on the server. ETag validation divides into the following two types:

  • Strong validation
  • Weak validation

Strong Validation

Weak Validation

Strong validation (using ETags with "strong" matching) requires that the content of a resource is identical, byte for byte, between the cached version and the server version. This means that if even a tiny part of the resource has changed on the server, such as just one byte, the cached version becomes invalid. In such cases, the client must ask the server for the resource again to get the updated version.


Weak validation (using ETags with "weak" matching) is more flexible than strong validation since it only requires that the resource has not been modified substantially since the cached version was last retrieved. What counts as a substantial change can be defined differently depending on the implementation, but it typically means a noticeable change to the end user. For example, changing the font size on a web page may not be considered a substantial change, but changing the main content of the page would be.


Overall, strong validation is more strict than weak validation, but can also be more accurate. Weak validation is more flexible, but may not always catch changes that are important to the end user.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved