2

While testing a way in Firefox to reload an HTML page without caching, I've included the following snippet in my code:

<script>
window.setTimeout(function () {
    location.reload(false);
}, 5000);
</script>

This reloads the page after 5 seconds, however I get shown the prompt: "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."

If there a way to do a silent refresh via Javascript, one that doesn't show any prompt? For instance, if I used the refresh Meta tag (HTML), my browser silently refreshes. I want to approximate that same experience, but via JS (and no cache). BTW mine is a Django web app, and I inject the JS code in my Django template.

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
  • This is standard behaviour to protect people from submitting form information more than once (eg, prevent double payments in an ecommerce system). Try telling the Javascript to direct to a 'new' page: `window.location.href = '/';` - I'm not sure if this fits your caching requirement, hence comment not answer. – Lewis Mar 16 '16 at 17:23
  • @lewis: this isn't exactly my home page, so I'll have to give a different href. But I see your point, let me try it out. – Hassan Baig Mar 16 '16 at 17:25
  • Now posted as an answer, with a fix for no caching. – Lewis Mar 16 '16 at 17:27

3 Answers3

0

Have you tried location.reload (true) ? If set to true, it will always reload from server. Set to false it'll look at the cache first.

Shilly
  • 8,511
  • 1
  • 18
  • 24
  • Shilly, oh I thought setting it to true means it'll always reload from server? – Hassan Baig Mar 16 '16 at 17:26
  • That's what I said. Set to true it'll always reload from server. Isn't that what's needed, since your first sentence is '... reload HTML page without caching.'? Im hoping that reloading from server will remove the confirmation popup. (But this wont make the post request again.) – Shilly Mar 16 '16 at 17:42
0

You are getting this prompt because you ask to reload a POST request. You should always get this prompt when reloading a POST request, as it is not a safe method

However, if you wish, you can explicitely resend a POST request (though you might have difficulties to find back the POST data previously sent). Or explicitely send a GET request to the same URL.

Antoine Pinsard
  • 33,148
  • 8
  • 67
  • 87
0

This is standard behaviour to protect people from submitting form information more than once (eg, prevent double payments in an ecommerce system). Try telling the Javascript to direct to a 'new' page:

Try using this, setting the url to your own;

window.location = "my.url/index.html?nocache=" + (new Date()).getTime();

Answer borrowed from here where there is also an explanation given for why this works -> How can I force window.location to make an HTTP request instead of using the cache?

Community
  • 1
  • 1
Lewis
  • 3,479
  • 25
  • 40
  • This works, I'm going to mark it. I don't suppose I can get rid of "back button" woes in this case, can I? I.e. I can view the content of the page post refresh if I simply press the back button. – Hassan Baig Mar 16 '16 at 17:36
  • What issue are you having with the back button? - As far as I know, this should treat pages normally, ie, act the same as if you had clicked an A link. – Lewis Mar 16 '16 at 17:38
  • I actually made a separate question about that here: http://stackoverflow.com/questions/36043335/back-button-on-browser-making-no-cached-page-accessible – Hassan Baig Mar 16 '16 at 17:55
  • Responded on new question. – Lewis Mar 16 '16 at 17:56