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
We live in a technologically advanced age where h...
Do you still remember the 5G "cloud supervis...
In most people's impressions, when talking ab...
[[419685]] The right secure access service edge (...
Kurun is a domestic merchant founded in 2019. Its...
I just don't love you anymore, a song that ca...
The road to advanced popular science of the obscu...
IP address is a term that everyone is familiar wi...
[[390976]] Compared with China Telecom and China ...
As the country vigorously promotes the developmen...
Recently, the Ministry of Industry and Informatio...
We often share the VPS hosting information provid...
The whois query of the domain name Servervy.com s...
IoT innovation has seen the increasing adoption o...
Today, the Asia-Pacific region ranks second in th...