Javascript redirect, fastest way to do this?


I am using javascript and localStorage

for redirection.
But I found that there are many ways to do this. Here are a few:

document.location
document.location.href
window.open(url,how)
window.location
top.location
window.navigate() //not sure that this works

      

and the html meta way

<meta http-equiv="REFRESH" content="0;url=http://www.google.com"/>

      

I'm just wondering which of the above (or any other code) would redirect faster. As for the information, I will use it to redirect (to the site) google chrome when a new tab is opened.

+3


source to share


1 answer


Metadata redirection is a terrible hack and it interrupts the back button. Never use it.

The rest is mostly equivalent. window.location

is the most common.



The fastest way might not be redirected from JS, but use <a href>

(with a click handler if you need to perform some operation before navigating), for example, allows browsers to prefetch DNS.

+4


source







All Articles