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
Earlier this month, I shared information about RA...
In the TCP/IP protocol, a connection is usually c...
There’s a lot of hype surrounding the next Wi-Fi ...
SpeedyPage is a foreign hosting company establish...
As 5G accelerates globalization, it will unlock u...
The optical module power is abnormal! What should...
What can 5G do? This is a question that everyone ...
In a recent filing with the Federal Communication...
5G can bring technology and innovation into the e...
DediPath launched a US Independence Day promotion...
According to statistics, in the fourth quarter of...
[[269494]] This article will focus on exploring a...
1. Introduction What is social engineering? Socia...
As global operators invest heavily in 5G, the top...
As urban populations continue to grow, the need f...