Ctrl + F5 in jquery to clear browser cache [duplic

2020-06-06 05:44发布

How to deep refresh window in jquery like you press f5 twice.currently i m using this.

<script>
window.onload = function() {
if(!window.location.hash) {
    window.location = window.location + '#loaded';
    window.location.reload();
}
}
</script>

Thanks ! and it should not take much time to refresh. my webpage is in php.

2条回答
你好瞎i
2楼-- · 2020-06-06 05:48

Ctrl+F5 basically used to refresh the client objects. Whenever we change anything into client scripts then we usually do ctrl+f5 to get the updates. Obviously, no developer want this. Well there is a fix for that.

Seperate your js code into external file and use it in your view.Then, you just need to set a version of JS file where you gonna place it (i.e. in your view)

<script src="path.js?123123" type="text/javascript"></script>

Suppose, path.js is your external JS file and ?123123 is basically a temporary versioning of the js file. So, the compiler will always treat it as new file by changing the number.

Hope this helps

查看更多
劳资没心,怎么记你
3楼-- · 2020-06-06 05:59

I think the reload function can take an argument that forces full refresh. ie:

window.location.reload(true);

For reference: https://developer.mozilla.org/en-US/docs/Web/API/Location/reload

查看更多
登录 后发表回答