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
LOCVPS (Global Cloud) is an early established Chi...
Industry insiders are familiar with LoRa technolo...
This article is reprinted from the WeChat public ...
introduce Today I would like to introduce an inte...
January 9th was a day of harvest for those who ha...
【51CTO.com Quick Translation】Introduction: Changi...
In 2020, China, which was the first to achieve a ...
Rate limiting is a key control mechanism used to ...
Fiberia.io is a new website, from the same compan...
Recently, the delayed 5G spectrum auction in Indi...
[[430598]] The shopping festival is here. If you ...
spinservers has released a promotion for March, o...
There may be a landmark turn in the U.S. stance t...
Author | Cai Zhuliang 1. Directory Network Protoc...
RackNerd recently launched the New Year 2024 spec...