Open In App

What is HTTP ETag?

ETag :

An entity tag (ETag) is an HTTP header used for Web cache validation and conditional request from browsers to resources. The value of an ETag is an identifier that represents a specific version of the resource. Additionally, ETags help prevents simultaneous updates of a resource from overwriting each other. Example of ETag header is

ETag: "version1"

Note :The value of the ETag header must be in double-quotes.



Working of ETag

Generating ETag Value

That’s entirely up to the application to generate it as it wants. It can be created and updated manually or can be auto-generated. Common methods of its auto-generation include using a hash of the resource’s content or just a hash of the last modification timestamp. The generated hash should be collision-free.

Validation of ETag value

It is just comparison of two values. It is divided into 2 parts



  1. Strong Validation
  2. Weak Validation

1.Strong Validation:

The different resource representations are byte-for-byte identical. This is the default validation of ETag and no special directive is used for it.

2.Weak Validation:

The two resource representations are semantically equivalent. For e.g. the current date displayed on the page might not be important for updating the entire resource for it.

References:

  1. https://en.wikipedia.org/wiki/HTTP_ETag
  2. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
Article Tags :