$window.location.reload(true) 等同于 CTRL+F5 吗?

Is $window.location.reload(true) the equivalent of CTRL+F5?

我正在尝试构建一个 "version updated" 组件,该组件将在网站更新时显示横幅并提示用户重新加载。不幸的是,当一些用户重新加载他们的页面时,他们的页面被缓存了,所以它不能正确更新。之前我们告诉他们按 CTRL+F5,但我正在寻找一种以编程方式执行此操作的方法。

我正在使用以下代码

this.$window.location.reload(true);

谁的函数签名是这样声明的:

reload(forcedReload?: boolean): void;

这是否意味着它将跳过缓存?当我尝试使用 CTRL+F5 时,index.html 在 Chrome 的网络选项卡中显示 200,但使用 $window.location.reload(true) 显示 304 [未修改]

不,不是(通过测试证明)

主要区别:Ctrl-F5 会导致所有附加资源也重新加载(脚本、图像...),而 reload(true) 不会,主页 (html ) 将被请求,但仍然可以从缓存中加载资源

你有没有试过类似的东西:

$window.location.href = currentUrl + '?' + new Date().getTime();

那应该强制冷刷新。

根据MDNwindow.location.reload中的forcedReload参数,设置为true时:

... causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.