F5 or by using the browser's reload button. So the questions that arise are, What use location.reload()?, and what is hard refresh? Let's find out the answer!
location.reload() method refreshes the current webpage from the browser's cache. Browser cache is temporary internet files that stores website's images, document, and data for faster future reloads.
location.reload() use this cache data to reload the webpages.
The Location reloads method can be invoked by a button click or by any other event. The most popular use is to automatically reload the webpage. This can be achieved by using
location.reload(). Look at the example below.
Automatic refresh works best for websites that need frequent reloads like
news websites, sports websites that show live scores, etc. But these websites need updated data, right from the server. So, we have to tweak the function a little bit to start refreshing the page from the server(Next topic).
Example of location.reload() with button:
Example of Automatic reloading of the webpage using setTimeout() method:
location.reload(true), can you spot the difference? Yes, a parameter is passed in the function, '
true'. This is how we refresh the webpage from the server, it's that easy. It is a boolean parameter, so, it has only two values true and false.
location.reload() has '
false' passed as a parameter. This parameter is for hard refresh from the server. When
false gets passed, the webpage reloads from the browser's cache. However, when
true gets passed, the browser requests server for a fresh copy of the webpage.
We use location.reload() to reload web document and it is the valid syntax. It is only the reload with forcedReload which is now deprecated.
To Solve location.reload(true) is deprecated Error we should use location.reload() without the forceReload flag.