gpt4 book ai didi

google-chrome - 301重定向后如何防止chrome从磁盘缓存中加载index.html

转载 作者:行者123 更新时间:2023-12-03 21:15:45 26 4
gpt4 key购买 nike

每当我们发布网站的新版本时,我们都会遇到 chrome 缓存问题,我们搜索了几天并添加/删除了任何可能导致此问题的 header 、元标记、nginx 配置等,或者据说可以修复它,但是什么都没有改变。 index.html 仍在缓存中,我们必须按 F5 才能查看随机计算机上的新更改,

该站点使用 angularjs 框架实现为 SPA,并使用 traefik 代理后面的 ngnix 托管,使用 traefik 规则,我们通过 301 响应强制将 HTTP 请求重定向到 HTTPS。

今天我发现了失败的场景!如果用户在地址栏中输入 https 协议(protocol)(例如 https://example.com ),一切正常,但如果用户返回并尝试访问 http://example.com , chrome 会通过 301 重定向缓存将用户重定向到 https,然后加载 index.html 的缓存版本,这不是我们想要的,缓存 301 重定向是可以的,但是我们希望 chrome 从服务器获取 index.html不从磁盘缓存加载它!

注意:只要用户使用 HTTPS,索引是从服务器加载或获得 304 响应,我们希望当用户仅输入域本身时发生这种情况,而不是使用 https。

这是添加到 index.html 的元标记:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />

这是我们的 nginx 配置的一部分:
...
http {
...
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=prerender_cache:100m max_size=10g inactive=1d;
proxy_cache_key "$request_method$host$request_uri$is_args$args";
...
server {
access_log /dev/stdout combined1;
listen 80 default_server;
server_name example.com;
root /app;
index index.html;
...
location ~ ^/(assets|static|styles) {
expires 31d;
add_header Cache-Control public;
}
location @asset_pass {
root app/;
try_files $uri =404;
}
location / {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalicate, post-check=0 pre-check=0";
try_files $uri @prerender;
autoindex on;
}
location ~ \.html$ {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalicate, post-check=0 pre-check=0";
}
}
}

现在的问题是:有没有办法解决这个问题,或者这是谷歌浏览器的默认行为?

感谢大家花时间阅读这个问题,如果问题太长,我们深表歉意。

最佳答案

你可以试试touch你的 index.html 文件,然后是响应头 last-modified将更改为最新日期时间,因此浏览器将认为此资源“已过时”,将应用最新的 301 规则;

关于google-chrome - 301重定向后如何防止chrome从磁盘缓存中加载index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53976518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com