Sometimes when you're building a website, you may need to reload or refresh the current page using JavaScript. For example, after a user submits a form, changes a setting, or if you want to show the most up-to-date information.
JavaScript makes this easy with a built-in method called window.location.reload()
.
In this short guide, you'll learn:
-
How to refresh the page with JavaScript
-
How to force a full refresh (not from cache)
-
When and why you might use it in your project
What is window.location.reload()
?
The window.location.reload()
method refreshes the current web page. It works the same as pressing the browser's refresh button.
Syntax:
-
By default, it reloads from the browser cache.
-
To force a reload from the server, pass
true
as an argument:
Example: Reload with a Button
What it does:
When the button is clicked, the page refreshes — just like hitting the refresh icon in the browser.
Force a Hard Reload (Bypass Cache)
?? Note: The true
argument is deprecated in modern browsers, and may be ignored. Most browsers only do a soft reload via JavaScript. For a guaranteed hard reload, it's better to use:
Or manually append a random query to bypass cache:
Common Use Cases
-
Refresh after submitting a form
-
Reload page after user updates settings
-
Get the latest data without reloading the whole app
-
Reset a game or interface to its initial state
Tips and Considerations
-
Avoid using reloads in SPAs (single-page apps) — use state updates instead.
-
Use reloads carefully on slow-loading pages.
-
Don’t reload unnecessarily — it can affect performance and user experience.
Summary
JavaScript’s window.location.reload()
is the easiest way to refresh the current web page. It works well for full-page applications, form resets, or getting the latest version of the page.
Key Takeaways:
-
window.location.reload()
reloads the current page -
true
argument forces a full reload (but may not be supported) -
Useful after changes, submissions, or for refreshing dynamic content