Cyber Week

Save big!

All courses under $5 - for a limited time!

Code has been added to clipboard!

JavaScript Refresh Page Method

Reading time 2 min
Published Aug 10, 2017
Updated Oct 2, 2019

JavaScript Refresh Page: Main Tips

  • The location.reload() method reloads the current web page.
  • The method gives the exact same result as pressing the RELOAD button in your browser.
  • The JavaScript reload page method loads the page from the cache by default. If the forceGet property is set to true, the page is reloaded from the server.
  • The JS reload page method does not have a return value.

Using location.reload()

The JavaScript refresh page function can reload the current resource. In most cases, a page is selected to be refreshed. The method also has other perks, such as helping you get the URL address of the current page, redirect the browser to another page, and, of course, refresh page JavaScript.

The following example contains the code you can use to reload a website. Click the Try it Live button, and make modifications to the script!

Example
location.reload();

The boolean parameter of this JS reload page method is automatically set as false. If you indicate true in the parentheses, the page will be reloaded from the server instead of cache.

In other words, by replacing the default false with true, you are forcing the website to be loaded from the server.

The JavaScript refresh page method is a popular choice among developers to reload webpages. The location of the document loaded on the window is found in the location variable. By invoking the location.reload(), you will perform the same kind of reload a regular browser refresh executes.

location.reload() Syntax

This is how you can call the refresh page JavaScript method from within your code (to reload from server):

location.reload(forceGet)

We have indicated that JavaScript refresh page command can have the forceGet parameter included in the the parentheses. This parameter always has a boolean value of either true or false However, it is optional.

The forceGet parameter should be only used when developers want to force the website to reload from the server. The JavaScript refresh page function without a parameter in its parentheses will reload the page from cache.

Example
location.reload(true);

Another way to reload the page is by using the timedRefresh command. You can specify how frequently to refresh the page, and it will do so automatically non-stop.

Example
function timedRefresh(time) {
	setTimeout("location.reload(true);", time);
}