Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between methods of reloading pages

window.location.reload()
history.go(0)
window.location.href=window.location.href

I noticed a website commenting that all 3 of these methods could be used to reload a page. Not content to trust it, I tried all 3 methods in IE8, FF3, and Opera 10. I noticed firefox performed a cache reload instead of a true reload for history.go(0), but otherwise saw no differences. However, I thought I'd ask the community here what differences they were aware of between these methods.

like image 824
Brian Avatar asked Feb 02 '10 22:02

Brian


1 Answers

The main difference between window.location.reload() and window.location.href=window.location.href is, that the first one will resend POST data if exists (the browser will ask you if you want to reload the page and resend the data), the second will just change the URL ignoring any POST data.

Regarding history.go(0), we are using the history object, so the browsers may use cached version of the page, stored somewhere in memory.

like image 160
Rafael Avatar answered Oct 27 '22 18:10

Rafael