Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript hard refresh of current page

People also ask

How do you hard refresh a page in JavaScript?

Location: reload(), The Location. reload() method reloads the current URL, like the Refresh button. Using only location. reload(); is not a solution if you want to perform a force-reload (as done with e.g. Ctrl + F5) in order to reload all resources from the server and not from the browser cache.

Can refresh the webpage in JavaScript by using?

Location. reload() method is used to refresh the webpage in javascript.

How do you refresh a JavaScript script?

To force a script reload and re-execute with JavaScript, we can make a copy of the original script, remove it, and then append it again. const scriptTag = document. createElement("script"); scriptTag.


Try to use:

location.reload(true);

When this method receives a true value as argument, it will cause the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.

More info:

  • The location object

window.location.href = window.location.href

For angular users and as found here, you can do the following:

<form [action]="myAppURL" method="POST" #refreshForm></form>
import { Component, OnInit, ViewChild } from '@angular/core';

@Component({
  // ...
})
export class FooComponent {
  @ViewChild('refreshForm', { static: false }) refreshForm;

  forceReload() {
    this.refreshForm.nativeElement.submit();
  }
}

The reason why it worked was explained on this website: https://www.xspdf.com/resolution/52192666.html

You'll also find how the hard reload works for every framework and more in this article

explanation: Angular

Location: reload(), The Location.reload() method reloads the current URL, like the Refresh button. Using only location.reload(); is not a solution if you want to perform a force-reload (as done with e.g. Ctrl + F5) in order to reload all resources from the server and not from the browser cache. The solution to this issue is, to execute a POST request to the current location as this always makes the browser to reload everything.