Reloading a Page using location.reload()
Using location.reload() Method
location.reload() method. This method reloads the current page, fetching the latest version from the server. Here’s an example:
// Reload the current page location.reload();
Reloading with Clear Cache
location.reload() reloads the page using the browser cache. However, there may be situations where you want to reload the page while bypassing the cache and fetching a fresh copy from the server. You can achieve this by passing
true as an argument to
location.reload(). Here’s an example:
// Reload the current page, bypassing the cache location.reload(true);
true, the browser will ignore the cached version and fetch a new copy of the page from the server.
Reloading a Page using window.location
window.location object. This object provides information about the current URL and can be used to navigate or reload the page. Here are the different methods you can use:
location.reload(), you can also use
window.location.reload() to refresh the current page. Here’s an example:
// Reload the current page window.location.reload();
This method behaves the same as
location.reload() and reloads the current page, including all its resources.
You can also change the value of
window.location.href to reload the page. Assigning the current URL to
window.location.href triggers a page reload. Here’s an example:
// Reload the current page window.location.href = window.location.href;
window.location.href to the current URL, the page will be reloaded.
Reloading a Page using Meta Tags
Using Meta Refresh Tag
An alternative method to refresh a page is by using the
<meta> tag with the
http-equiv attribute set to “refresh”. This meta tag instructs the browser to reload the page after a specified interval. Here’s an example:
<!-- Reload the page after 5 seconds --> <meta http-equiv="refresh" content="5">
In this example, the page will automatically reload after 5 seconds. You can adjust the value of the
content attribute to specify the desired interval in seconds.
// Modify the meta tag to refresh the page after 10 seconds const metaTag = document.querySelector('meta[http-equiv="refresh"]'); metaTag.setAttribute
Hi all, my name is Angelika and I am one of the authors of the EasyTechh website. Like the rest of our team I am incredibly ambitious and I love helping people.
That’s why I write here and not only here 😉 I write interesting and useful for people articles in the IT sphere and a little bit about life.