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.
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
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!
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.
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.
function timedRefresh(time) {
setTimeout("location.reload(true);", time);
}