Is there any particular advantage/disadvantage in JavaScript memory consumption between using location.href = url
as opposed to location.assign(url)
?
I guess I'm wondering if it takes more memory to access the method as opposed to setting the property.
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History , meaning the user won't be able to use the back button to navigate to it.
assign() The Location. assign() method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.
The location. href property sets or returns the entire URL of the current page.
window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).
I personally prefer calling the function instead, because calling a function gives me a better impression that something is running and that is not only a value of a variable that is changing.
But probably yes, it may be true that location.href = url;
is faster than location.assign(url)
, although it may depend on the JavaScript engine implementation, see the test I've just created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With