首页主机资讯Expires, Last-Modified, Etag缓存机制

Expires, Last-Modified, Etag缓存机制

时间2023-11-18 15:16:03发布访客分类主机资讯浏览1214
导读:Expires, Last-Modified, and Etag are all mechanisms used for caching in web browsers.1. Expires: The Expires header spec...

Expires, Last-Modified, and Etag are all mechanisms used for caching in web browsers.
1. Expires: The Expires header specifies a date and time after which the cached resource is considered expired and should no longer be used. The browser checks the Expires header before making a request to the server, and if the current date and time is later than the specified date and time, it sends a request to the server to get the latest version of the resource. This mechanism is based on the assumption that the resource will not change before the specified expiration date.
2. Last-Modified: The Last-Modified header is sent by the server in response to a request for a resource. It contains the date and time when the resource was last modified. When the browser receives this header, it stores the date and time. The next time the browser needs to fetch the same resource, it sends a request to the server with an If-Modified-Since header containing the stored date and time. If the resource has not been modified since the specified date and time, the server responds with a 304 Not Modified status code and the browser uses the cached version of the resource. Otherwise, the server sends the updated version of the resource.
3. Etag: The Etag (entity tag) header is another way for the server to identify a specific version of a resource. It is typically a hash or a unique identifier generated by the server based on the resource's content. Similar to the Last-Modified header, when the browser receives the Etag header, it stores the value. The next time the browser needs to fetch the same resource, it sends a request to the server with an If-None-Match header containing the stored Etag value. If the Etag value matches the current version of the resource on the server, the server responds with a 304 Not Modified status code and the browser uses the cached version. If the Etag value does not match, the server sends the updated version of the resource.
Both Last-Modified and Etag are used to validate whether the cached version of a resource is still valid, but they have different approaches. Last-Modified relies on the server's timestamp of the resource's last modification, while Etag relies on a unique identifier generated by the server.

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Expires, Last-Modified, Etag缓存机制
本文地址: https://pptw.com/jishu/544763.html
fastlane的使用及文件编写 js实现函数柯里化

游客 回复需填写必要信息