HTML 页面未缓存

发布时间:2021-03-05 17:15

我已经检查了我的本地浏览器设置并且没有任何内容阻止缓存(我看到同一页面中的其他几个网络请求已成功加载缓存)。每当我离开页面并返回时,此资源总是加载(并且需要一两秒钟)。它似乎根本没有使用缓存。这是我的标题:

一般

Request URL: https://example.website.stage/htmlpage/
Request Method: GET
Status Code: 200 
Remote Address: ~omitted~
Referrer Policy: strict-origin-when-cross-origin

响应头

alt-svc: clear
cache-control: public, max-age=43200, immutable
content-length: 68988
content-security-policy: frame-ancestors 'self'
content-type: text/html; charset=utf-8
date: Fri, 05 Mar 2021 17:01:55 GMT
server: istio-envoy
set-cookie: session_timer=session_timer; Expires=Fri, 05-Mar-2021 17:16:55 GMT; Secure; Path=/
strict-transport-security: max-age=31536000; includeSubDomains
vary: Cookie
via: 1.1 google
x-content-type-options: nosniff
x-envoy-upstream-service-time: 2618
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block

请求标头

:authority: example.website.stage
:method: GET
:path: /htmlpage/
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cookie: ~omitted~
referer: https://example.website.stage/htmlpage
sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: same-origin
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36
回答1

想通了。如果 cookie 不匹配,响应标头 vary: Cookie 会导致所有未来的请求跳过缓存,并且由于我们的 cookie 包含时间戳,它永远不会匹配!