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
1. Overview This article mainly explains MaxCompu...
[[188315]] [51CTO.com original article] In the ne...
One year after 5G was officially put into commerc...
As a product of the deep integration and applicat...
Megalayer has launched its latest promotion, main...
The advent of 5G technology promises lightning-fa...
[[425641]] As a front-end framework for mobile de...
[51CTO.com original article] On February 8, China...
I think everyone is still curious about this ques...
Optical chips and optical components are the basi...
Recently, more than 560,000 5G users in South Kor...
Hello everyone, I am Xiao Fu. RIP Defects When ta...
In many ways, 4G networks are already falling beh...
DiyVM is a Chinese hosting company founded in 200...
HostXen was founded in 2014 and provides cloud se...