preface

In the HTTP1.1 specification, a new HTTP header is added: ETag. For the average developer, this HTTP header is probably not something you would normally touch. Just because the header is not accessible or used infrequently does not mean it is not important. When ETag is used properly, it can reduce the bandwidth pressure on the server.

What is ETag?

Etag is short for Entity Tag, which can be understood as “Entity value of requested variable”. Etag is the identification of a resource on the server and is passed to the client in the HTTP response header. A server resource can be a Web page, JSON, XML, etc. The server is solely responsible for determining what tokens are and what they mean and passing them to the client in the HTTP response header. For example, when the browser requests a resource for the first time, the server returns ETag: “50b1C1d4f775C61 :df3″. When the browser requests the resource again, the browser will Match if-none-match: W/” 50B1C1D4F775C61: DF3 “is transmitted to the server. The server takes the ETAG and compares whether the resource has changed. If the resource has not changed, the server returns the 304HTTP status code without returning the specific resource.

Etag practical examples

We can use Etag to take advantage of the browser cache and reduce the bandwidth strain on our server. This can improve performance on the server side (data transfer). Seven niuyun file storage, the use of the Etag attribute. Now, I request a resource on the seven Niuyun:

As you can see from its response header, it returns the Etag field to us. The Etag value is fPL1rXE-k20CYSLU89yTZuq3yDDk.

Refresh the resource again:

conclusion

This article is only a conceptual explanation of Etag, and combined with the seven Niuyun object storage example, analyzes the process of Etag cache. There are a lot of things about Etag that have not been explained in detail, such as how Etag is calculated, what last-modified/if-Modified-since is, and how Etag is used in practice.