Home >Web Front-end >JS Tutorial >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 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!