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);
}
What Is JavaScript Used For?
Tutorial
Introduction
Output
Syntax
Comment
Commands
Operators
Comparison and Logical Operators
Data Types
Math.random()
Type Conversion
Function Definitions
Events
Objects
Object Properties
Prototype
Array
Sorting Arrays
Strings
Numbers
Number Format
Math Object
Onclick Event
Date
Date Formats
Scope
Regular Expressions
Reserved Words
Common Mistakes
Performance
Forms
Form Validation
Window: The Browser Object Model
Popup Boxes
Cookies
JSON
AJAX Introduction
AJAX Form
Automatic File Download
Functions
Array Methods
String Methods
Date Methods
Timing Events
Cheat Sheet
JavaScript in HTML
HTML DOM Methods
HTML DOM Changing HTML
HTML DOM Animation
HTML DOM EventListener
HTML DOM Navigation
HTML DOM NodeList
HTML DOM Element Nodes
Array Functions
Boolean
Calling a Function
Date Functions
Global Objects
Input Text
Operator
Statements
String Functions
Math
Math.random
Number
RegEx
alert
array.filter
array.length
array.map
array.reduce
array.push
array.sort
break and continue
className
confirm
decodeURIComponent
for
forEach
if
indexOf
innerHTML
location.reload
number.toString
onclick
onload
parseInt
prompt
replace
setAttribute
setInterval
setTimeout
slice
splice
string.includes
string.indexOf
string.split
style.display
submit
substr
substring
switch
test
throw, try and catch
toLowerCase
toUpperCase
use strict
while
window.history
window.location
window.navigator
window.screen