Call location.reload() to reload the current page, exactly as the browser's reload button does. It takes no standard arguments. The old reload(true) form, meant to skip the cache, is a non-standard parameter that MDN lists as supported only in Firefox, so other browsers ignore the true. history.go(0) also reloads.
| Code | What happens | Adds a history entry? |
|---|---|---|
| location.reload() | Reloads the current URL | No |
| history.go(0) or history.go() | Same result as location.reload() | No |
| location.replace(url) | Loads url and replaces the current entry | No, Back skips the old page |
| location.assign(url) | Loads url as a new step | Yes |
| <meta http-equiv="refresh" content="30"> | Reloads after 30 seconds, no script needed | No |
Updated
Reloading is one line of code, but the reasons people reach for it vary: picking up new data, resetting a stuck state, refreshing a dashboard on a timer or forcing a new version of the site. This guide shows the standard call, what the older variations really do, and how to avoid a reload entirely when fetching fresh data is all you need.
The click handler calls the standard reload with no argument.
<button type="button" id="reload">Refresh</button>
<script>
document.getElementById("reload")
.addEventListener("click", () => location.reload());
</script>Hidden tabs are skipped, and a tab that comes back after the interval reloads straight away.
const EVERY_MS = 60_000;
let last = Date.now();
setInterval(() => {
if (document.visibilityState === "visible" && Date.now() - last >= EVERY_MS) {
location.reload();
}
}, 5_000);
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible" && Date.now() - last >= EVERY_MS) {
location.reload();
}
});The sessionStorage flag survives the reload in the same tab, so the second load skips it.
if (!sessionStorage.getItem("reloadedOnce")) {
sessionStorage.setItem("reloadedOnce", "1");
location.reload();
}Browsers only show the prompt after the person has interacted with the page, and they use their own wording.
let dirty = false;
form.addEventListener("input", () => { dirty = true; });
window.addEventListener("beforeunload", (e) => {
if (dirty) e.preventDefault();
});
A full reload throws away the whole page: the DOM, every variable, open menus, typed input and usually the scroll position. That is the right reset when the page is in a bad state or a new version must load.
When you only need new numbers on a dashboard, call fetch, update the part of the page that changed and leave the rest. It is quicker, uses less data and does not flash the screen.
A normal reload lets the browser revalidate cached files with the server, but files served with a long cache lifetime can still come straight from the cache. Code that tries to force a hard refresh from JavaScript cannot fix that across browsers.
The dependable fix lives on the server and in the build: put a content hash in script and style file names so every deploy gets new URLs, and serve the HTML with a short or no-cache lifetime so it always points at the latest files.
Not reliably. The forceGet argument is not part of the HTML standard, and MDN notes only Firefox supports it. Other browsers ignore it and do a normal reload. To make sure people get new files, version your asset URLs or set proper Cache-Control headers.
reload() always reloads the current document. Assigning href starts a navigation to that URL, and when the URL contains a #fragment the browser only scrolls to the fragment, so nothing reloads. Use reload() when a reload is what you want.
Without script, add <meta http-equiv="refresh" content="30"> to the head. With script, setTimeout(() => location.reload(), 30000). Use auto refresh sparingly: MDN warns that unexpected refreshes can disorient people and conflict with WCAG guidance on timing.
No. Calling reload on another origin's Location throws a SecurityError DOMException, so a script inside an iframe from a different site cannot reload the parent, and the parent cannot reload it that way.
Mark that you already reloaded, for example with a sessionStorage flag or a query parameter such as ?r=1, and check it before calling reload. Without a guard, code that reloads on load creates an endless loop.
Related: JavaScript localStorage guide, Fetch data without reloading, JavaScript event listeners, Scroll to an element, HTML boilerplate.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.