让 Chrome 和 Safari 浏览器在重定向后显示缓存的页面

Make Chrome and Safari show cached page after redirect

本文关键字:缓存 显示 重定向 Chrome Safari 浏览器      更新时间:2023-09-26

我有一个登录表单(POST,https),在成功登录后将用户重定向到页面。(这是通过nodejs express中的302重定向完成的)

下一页可缓存很长时间。

在 Firefox 和 Explorer 中,下一页是从缓存中加载的。

在 Safari 和 Chrome 中,下一页是从服务器加载的。

我希望Chrome和Safari也从缓存中加载此页面。(像js和css这样的子资源是从所有浏览器中的缓存中加载的)

下一页的标题是:

Cache-Control:private, max-age=2592000
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Sat, 27 Dec 2014 00:27:03 GMT
Strict-Transport-Security:max-age=31536000; includeSubDomains
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Content-Type-Options:nosniff
X-XSS-Protection:1; mode=block

(我也有饼干套装)

如果我在第二页上打开 javascript 控制台,然后键入

document.location='/secondPage';

页面从缓存加载。

你知道吗?

一个糟糕的解决方法是返回一个 html 文档,如下所示的 Chrome 和 Safari 文档,而不是在帖子后重定向:

<html><head><script>document.location='/secondPage';</script></head></html>

通过这种方式,从缓存中获取第二页。