2

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.

Bugfixer
  • 2,547
  • 2
  • 26
  • 42
  • i said clear cache while refreshing.its like u press f5 twice – Bugfixer Feb 21 '15 at 09:32
  • read the accepted answer, `can be set to true to reload from the server rather than the cache.` – CRABOLO Feb 21 '15 at 09:32
  • suppose i have link, i click on that link it redirect me to the next page.there i want a deep refresh.i cannot use location.reload there.is there anything which i can put in my php page so that it gives a refreshed view not old same view. – Bugfixer Feb 21 '15 at 09:36
  • above solution works but first page open and then again refresh. – Bugfixer Feb 21 '15 at 09:37
  • 1
    @Kiranarya - If I remembered correctly there's a trick that you can do to force it to load the page without using the cache by inserting a query: `https://www.google.com/?t=some_time` – Derek 朕會功夫 Feb 21 '15 at 09:40
  • @Derek朕會功夫 check this answer http://stackoverflow.com/questions/8577762/php-redirect-that-force-refresh-ctrlf5 but i dont understand what it means plz – Bugfixer Feb 21 '15 at 09:43
  • @Kiranarya The answer there is exactly the one I mentioned. I used time instead of "big number" because it will be unique every time. – Derek 朕會功夫 Feb 21 '15 at 09:44
  • @Derek朕會功夫 thanks 4 help but its not working.:-) – Bugfixer Feb 21 '15 at 09:53
  • @Kiranarya It should work. – Derek 朕會功夫 Feb 21 '15 at 09:53

2 Answers2

2

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

Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • 1
    It only works in firefox – Davide Pizzolato May 30 '22 at 14:52
  • @professor-abronsius you might want to consider removing this answer. The linked documentation indicates that this only works in FF and is only because of a mistake. It should always be `window.location.reload()` without arguments. – Giwan Jun 28 '22 at 09:49
0

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

CY_Techie
  • 86
  • 7