The generation of etag needs to meet several conditions, at least loosely meet
The above conditions are theoretical conditions for validity. How should they be handled in actual practice? Let's see how it is done in nginx ETag generation in nginxI looked through the nginx source code and translated it into pseudo code as follows: concatenated from last_modified and content_length etag = header .last_modified + header .content_lenth The source code is located at: ngx_http_core_modules.c etag -> value .len = ngx_sprintf ( etag -> value .data , "\"%xT-%xO\"" , Summary: In nginx, etag is a hexadecimal combination of the Last-Modified and Content-Length fields in the response header. Just find an nginx service in my k8s cluster to test it $ curl --head 10.97.109.49 Calculate Last-Modified and Content-Length from etag, use js to calculate as follows, the results are consistent > new Date ( parseInt ( '5cbee66d' , 16 ) * 1000 ) .toJSON ( ) ETag algorithm in Nginx and its shortcomingsNegotiation cache is used to calculate whether the resource returns 304. We know that there are two ways to negotiate cache
Since ETag in nginx consists of Last-Modified and Content-Length, it is considered an enhanced version of Last-Modified. So where is the enhancement? Last-Modified is represented by a unix timestamp, which means it can only act on changes in seconds, while ETag in nginx adds an additional condition of file size. The next question is: if the ETag value in the http response header changes, does it mean that the file content has definitely changed? Answer: No. Therefore, using nginx to calculate 304 has certain limitations: the file is modified within 1 second and the file size remains unchanged. However, the probability of this happening is extremely low, so under normal circumstances, an imperfect but efficient algorithm can be tolerated. The article comes from: Front-end Restaurant. If you wish to reprint this article, please contact the Front-end Restaurant ReTech Toutiao account. github: https://github.com/zuopf769 |
<<: Distributed ID Solution Detailed Explanation
>>: Seven steps to easy network segmentation
Today’s enterprise manufacturing facilities are u...
Speaking of 5G, what do you think of first? If yo...
Note: This article describes how to intelligently...
Cellular wireless networks are an attractive alte...
Fiber to the home (FTTH) is the transmission of c...
In July 2021, Gartner, a global authoritative IT ...
Lao Lao Noodles Source: https://www.nowcoder.com/...
HTTP cache is very critical for front-end perform...
[[400276]] This article is reprinted from the WeC...
CMIVPS sent a 10% discount code for all VPS, incl...
Preface Traditional IP packet switching networks ...
Author: Wang Rui, unit: Hebei Mobile Labs Guide A...
The benefits of 5G and edge computing in the ente...
Have you ever thought about how long it has been ...
At the recently concluded MWC 2018, 5G became a h...