117.info
人生若只如初见

Expires, Last-Modified, Etag缓存机制

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.

未经允许不得转载 » 本文链接:https://www.117.info/ask/feb79AzsLBwdTDFY.html

推荐文章

  • js实现函数柯里化

    函数柯里化是一种将多个参数的函数转换为一系列接收单个参数的函数的技术。在JavaScript中,可以通过以下方式实现函数柯里化: 使用闭包:创建一个外部函数来接收...

  • fastlane的使用及文件编写

    Fastlane是一个iOS和Android的自动化构建和发布工具,它可以帮助开发者自动化繁琐的构建、测试、打包和发布过程。使用Fastlane,开发者可以通过简单的配置文件,...

  • 性能优化之 preload、prefetch、preconnect 的区别与使用

    preload、prefetch、preconnect 是网页性能优化的常用手段,它们可以预加载资源、预解析 DNS、建立连接,从而提升网页的加载速度和用户体验。 preload:preload ...

  • Promql 函数 rate() 和 irate() 辨析

    PromQL 函数 rate() 和 irate() 都是用于计算时间序列的变化率的函数,但有一些区别。
    rate() 函数计算的是在指定时间范围内的平均变化速率。它将时间范围内...