Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why location.reload() is slower than the other page reload methods?

Tags:

javascript

Few months ago I posted this answer about how to refresh the page via JavaScript.

I provided a JSFIDDLE DEMO too:

var solutions = [
    function () { location.reload(); },
    function () { history.go(0); },
    function () { location.href = location.href; },
    function () { location.href = location.pathname; },
    function () { location.replace(location.pathname); },
    function () { location.reload(false); },
];

$("[data-func]").on("click", function () {
    solutions[parseInt($(this).attr("data-func"))]();
});

Someone noticed that location.reload() is slower than the other methos. Now I can see the same thing.

Why is it slower? Why the others are faster?

like image 934
Ionică Bizău Avatar asked Dec 31 '13 11:12

Ionică Bizău


People also ask

What is the difference between location reload () and window location reload ()?

location. reload(true); reloads the page from the server instead of from the cache, window. location. reload(); would do the same thing as location.

What is location reload ()?

The location. reload() method reloads the current URL, like the Refresh button.

Is location reload deprecated?

location. reload is falsely reported as a deprecated function.

Is location reload asynchronous?

Since it's asynchronous, the Javascript continues running (it doesn't wait for the AJAX request to complete in order to continue to run the rest of your code ( window. location. reload() ).


2 Answers

Been looking for this myself and the best reference I could find is actually on w3schools.com

http://www.w3schools.com/jsref/met_loc_reload.asp

location.reload(forceGet)

forceGet:

false - Default. Reloads the current page from the cache.

true - The current page must be reloaded from the server

like image 141
Wildcard27 Avatar answered Nov 15 '22 16:11

Wildcard27


From the Mozilla Developement Network I guess the .reload method may fetch all files from the Server again. This would be similar to a CTRL + F5 reload.

The location.href for example, simply follows the link which may be cached. As for the MDN definition the behave is not clearly defined so I guess its browser and case specific behave.

like image 35
Panade Avatar answered Nov 15 '22 18:11

Panade