Get in Touch With Us

Submitting the form below will ensure a prompt response from us.

Refreshing a web page is one of the simplest actions you can perform using JavaScript, but it plays a critical role in many interactive web applications. One of the commonly used commands for this is location. reload(true). Although straightforward, this method has nuances that every developer should understand, especially since the behavior of true has changed over time.

In this guide, we’ll dive into what Javascript:Location.Reload(True) does, how it works, when to use it, and what has changed in modern browsers.

What is Javascript:Location.Reload(True) in JS?

Location.reload() is a JavaScript method that reloads the current URL, just like refreshing the page using the browser’s refresh button (F5).

Basic Syntax:

location.reload();

This reloads the page from the browser cache by default.

What Does location.reload(true) Mean?

In older versions of JavaScript and some legacy browsers, location. reload(true) was used to force a reload from the server rather than from the browser cache.

Example:

location.reload(true); // forces page reload from server (deprecated)

However, the true argument is now deprecated and has no effect in modern browsers like Chrome, Firefox, and Edge. Today, whether the page reloads from the server or cache is controlled by the browser itself.

Current Usage: Just Use location.reload()

If you’re writing modern JavaScript, the recommended usage is simply:

location.reload();

This works well in almost all cases unless you’re specifically handling cache issues.

Forcing a Fresh Reload (Workaround)

If you want to ensure that the page loads fresh (as location.reload(true) once did), a better approach today is to modify the URL with a cache-busting query string:

window.location.href = window.location.href.split('?')[0] + '?cache=' + new Date().getTime();

Or redirect to the same page using:

window.location.replace(window.location.pathname + '?refresh=' + new Date().getTime());

This tricks the browser into thinking it’s a new page, thereby bypassing the cache.

Common Use Cases

After Form Submission

To reload the page and show updated data:

document.getElementById("submitBtn").onclick = function () {

// Submit logic here...

location.reload();

};

After Logout

To clear user sessions and redirect:

function logoutUser() {

// Perform logout

sessionStorage.clear();

location.reload();

}

Refreshing a SPA or Dashboard

Used in interval-based data refresh scenarios:

setInterval(() => {

location.reload();

}, 60000); // reloads every 60 seconds

Deprecation Warning: location.reload(true)

Modern browsers ignore the true parameter, and some may even warn you in the console:

Warning: location.reload(true) is deprecated and ignored.

So, avoid using it in production code. Use cache-busting or service worker techniques instead for more robust solutions.

Pro Tip: Use DevTools to Disable Cache

If you’re testing and need to force a fresh reload:

  1. Open Chrome DevTools (F12)
  2. Check “Disable Cache” in the Network tab
  3. Reload using location.reload()

This ensures the page reloads from the server while you’re developing.

Alternative: window.location.hrlef

If you want more control, you can also reload or redirect using:

window.location.href = window.location.href;

Or redirect to a specific route:

window.location.href = '/dashboard';

This is a more flexible way to navigate or reload with parameters.

Conclusion

location.reload(true) was once used to force a server reload, but in modern JavaScript, this usage is deprecated. The correct and safe method today is simply location.reload(). If you want to bypass the cache, use a URL-based trick or control caching via HTTP headers or service workers.

Understanding this subtle difference helps write more reliable and modern JavaScript for real-world applications.

About Author

Jayanti Katariya is the CEO of Moon Technolabs, a fast-growing IT solutions provider, with 18+ years of experience in the industry. Passionate about developing creative apps from a young age, he pursued an engineering degree to further this interest. Under his leadership, Moon Technolabs has helped numerous brands establish their online presence and he has also launched an invoicing software that assists businesses to streamline their financial operations.

Related Q&A