-1

Is there a jQuery method to reload the page that will work in all browsers and cause the page to be reloaded from the server?

My intranet users leave their browsers open often for weeks on end, and when I make a fix or change to a javascript file that is referenced in the page's < head > section, I want the page to be reloaded and to get the latest version of that javascript file.

My plan was to keep a record in a database on the server and poll the database periodically via ajax in order to determine if the relevant timestamp in the database is more recent than the datetime the page was loaded, and if so, force the page to reload.

See: Force a reload of page in Chrome using Javascript [no cache]

Community
  • 1
  • 1
Tim
  • 8,669
  • 31
  • 105
  • 183
  • Does a [Meta Refresh](http://en.wikipedia.org/wiki/Meta_refresh) not meet your needs? – Rick Liddle Feb 08 '13 at 14:25
  • My question is not how to do it but whether there's a jQuery method to do it :-) Please remove the downvote. – Tim Feb 08 '13 at 14:31
  • @Alex K. Also, are you sure these answers work in all browsers, including Chrome? – Tim Feb 08 '13 at 14:33
  • @Rick Liddle: No, meta refresh does not meet my needs. I only want to reload when it's necessary. – Tim Feb 08 '13 at 14:34
  • @Alex K. And are you certain the answers will work on all future devices. Someone was too quick to downvote this question because of their personal biases. – Tim Feb 08 '13 at 14:54

2 Answers2

7

No jQuery required, just plain old JavaScript

window.location.reload()
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • mark that eventual login and other posted data will be lost – Vogel612 Feb 08 '13 at 14:24
  • that function won't reset the cache unless you pass true as its parameter – pwolaq Feb 08 '13 at 14:26
  • @Rory McCrossan: but I did not ask if jQuery was required. I asked whether there was a jQuery method. If I'm going to be using jQuery, I want to future-proof my code by doing things "the jQuery way", trusting that it will work on, say, the iPad and Android tablets and on any other device that comes down the pike. My question does not deserve a downvote. – Tim Feb 08 '13 at 14:52
  • @Tim I didn't downvote you. I was just advising you that jQuery is not always needed - in fact it should be used as sparingly as possible. People downvoted your question as you apparently did not search as there is already a question covering this topic. – Rory McCrossan Feb 08 '13 at 14:54
  • But those answers do not answer my specific question. – Tim Feb 08 '13 at 14:55
  • `You don't need jQuery to do this. Embrace the power of JavaScript.` is the answer from someone with an axe to grind. It doesn't answer the specific question either. – Tim Feb 08 '13 at 14:57
  • It is the answer! jQuery is a framework which sits on top of JavaScript. Javascript has the `window` object which you use to access history and navigation methods. That is why no jQuery is used here. You have an answer. – Rory McCrossan Feb 08 '13 at 15:02
  • @Rory McCrossan: There may in the future be devices which require some sort of workaround (just as, in the past, the .reload() approach has not always worked on every browser). So, if there were a jQuery method I would use it over a "raw" javascript approach. – Tim Feb 08 '13 at 17:14
1
window.location.reload(true)

is a better option because it clears the cache

pwolaq
  • 6,343
  • 19
  • 45
  • 1
    but apparently isn't cross-browser: http://stackoverflow.com/questions/10876244/browser-support-for-window-location-reloadtrue – Dead.Rabit Oct 25 '13 at 13:03