Home > other >  How to hard reload/refresh a page using javascript
How to hard reload/refresh a page using javascript

Time:09-23

How do we do a hard reload/refresh in Chrome using Javascript?

window.location.reload(true);
location.reload(true);

didn't do it for me.

===========================

What I meant by 'didn't do it for me...'

The session cookies (ex. JSESSIONID) were not renewed specially the HttpOnly ones.

What I want to achieve...'

  1. I wanted to reload the page like it's the first time I accessed the URL.
  2. I wanted to simulate the steps below (which is like accessing the URL for the first time)
   - Open browser
   - Type URL
   - Hit Enter

I wonder if there is a more powerful Javascript command that reloads as if it is the first time.

CodePudding user response:

location.reload() should work. Works for me!

Can you share the rest of your code?

CodePudding user response:

The best (and practically only) way to ensure a page is hard reloaded is by using your server. One of the ways you can do this is by serving headers, when a page is requested, that invalidate resources such as Cache-Control which will tell the browser to not cache resources and always revalidate resources which means everything must be redownloaded each time.

I would not recommend serving this header on every request in your production application, though.

Cache-Control: no-cache, must-revalidate
  • Related