Home >Web Front-end >JS Tutorial >How to Force a Hard Refresh of a Web Page with JavaScript?

How to Force a Hard Refresh of a Web Page with JavaScript?

Susan Sarandon
Susan SarandonOriginal
2024-10-19 15:48:021065browse

How to Force a Hard Refresh of a Web Page with JavaScript?

Force a Hard Refresh of the Current Page Using JavaScript

Performing a hard refresh forces the web browser to retrieve a fresh copy of the current page, including all external resources such as images, JavaScript, and CSS. In JavaScript, this can be achieved by utilizing the location.reload() method.

Solution:

location.reload(true);

However, it's important to note that this solution may not work consistently across all browsers. According to the MDN documentation for location.reload():

"Note: Firefox supports a non-standard forceGet boolean parameter for location.reload(), to tell Firefox to bypass its cache and force-reload the current document. However, in all other browsers, any parameter you specify in a location.reload() call will be ignored and have no effect of any kind."

When the location.reload() method receives a true value as an argument, it instructs the browser to always retrieve the page from the server, bypassing any cached versions. If a false value or no argument is provided, the browser may choose to load the page from its cache.

For more information on this method and its limitations, please refer to the following resources:

  • The location object: https://developer.mozilla.org/en-US/docs/Web/API/Location

The above is the detailed content of How to Force a Hard Refresh of a Web Page with JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn