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

早过忘川 提交于 2020-01-23 11:24:48

问题


I am attempting to build a "version updated" component that will show a banner when the website has been updated and prompt a user to reload. Unfortunately when some users reload their page is cached so it does not update properly. Previously we have told them to press CTRL+F5 but I am looking for a way to do this programatically.

I am using the following code

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

Whose function signature is declared like so:

reload(forcedReload?: boolean): void;

Does this mean that it will skip the cache? When I try it out a CTRL+F5 the index.html shows a 200 in the Network tab of Chrome but using $window.location.reload(true) shows a 304 [Not Modified]


回答1:


According to MDN the forcedReload parameter in window.location.reload, when set to 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.




回答2:


No it's not (proven by testing)

The main difference: Ctrl-F5 will cause all the attached resources also to reload (scripts, images ...) while the reload(true) will not, the main page (html) will be requested but resources can still be loaded from cache




回答3:


Did you try something like:

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

That should force a cold refresh.



来源:https://stackoverflow.com/questions/45630011/is-window-location-reloadtrue-the-equivalent-of-ctrlf5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!