HTTP Headers

2024 年 4 月 15 日

HTTP headers - HTTP | MDN

HTTP 标头(header) - HTTP | MDN

Client hints

HTTP Client hints - HTTP | MDN

Client hints are a set of HTTP request header fields that a server can proactively request from a client to get information about the device, network, user, and user-agent-specific preferences. The server can determine which resources to send, based on the information that the client chooses to provide.
客户端提示是一组 HTTP 请求标头字段,服务器可以主动向客户端请求这些字段,以获取有关设备、网络、用户和用户代理特定首选项的信息。服务器可以根据客户端选择提供的信息来确定要发送哪些资源

The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and shared caches (e.g. Proxies, CDNs).
Cache-Control HTTP 标头字段在请求和响应中保存指令(指令),用于控制浏览器和共享缓存(例如代理、CDN)中的缓存。

HTTP 缓存

Cache-Control

Cache-Control - HTTP | MDN

RequestResponse
max-agemax-age
max-stale-
min-fresh-
-s-maxage
no-cacheno-cache
no-storeno-store
no-transformno-transform
only-if-cached-
-must-revalidate
-proxy-revalidate
-must-understand
-private
-public
-immutable
-stale-while-revalidate
stale-if-errorstale-if-error

directives

max-age

The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated.
max-age=N 响应指令指示响应在生成响应后 N 秒内保持新鲜状态。

Note that max-age is not the elapsed time since the response was received; it is the elapsed time since the response was generated on the origin server. So if the other cache (s) — on the network route taken by the response — store the response for 100 seconds (indicated using the Age response header field), the browser cache would deduct 100 seconds from its freshness lifetime.
请注意, max-age 不是自收到响应以来经过的时间;它是自源服务器上生成响应以来所经过的时间。因此,如果响应所采用的网络路由上的其他缓存将响应存储 100 秒(使用 Age 响应标头字段表示),则浏览器缓存将从其新鲜度中扣除 100 秒寿命。

Cache-Control: max-age=604800
Age: 100

s-maxage

s-maxage 响应指令指示响应在共享缓存中保持新鲜状态的时间。私有缓存会忽略 s-maxage 指令,并覆盖由 max-age 指令或共享缓存的 Expires 标头(如果存在)指定的值。