location.reload(true) is deprecated location.reload(true) is deprecated javascript javascript

location.reload(true) is deprecated


You can use location.reload() without the forceReload flag.This is just deprecated because it is not in the spec: https://www.w3.org/TR/html50/browsers.html#dom-location-reload


If you look at interface definition for Location you will see the following:

/**  * Reloads the current page.  */reload(): void;/** @deprecated */reload(forcedReload: boolean): void;

Using location.reload() is the valid syntax. It is only the reload with forcedReload which is deprecated.

In your case changing location.reload(true) to location.reload() to resolve your issue.


Since the forceReload parameter is deprecated, as 3 people already mentioned, it is also ignored by some browsers already.

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.

location.reload() is only executing a GET request.

So I came to the workaround to place an empty form on the Angular app with method="POST" and action="https://example.org/" and then submitting that form from code-behind when wanted.

Template:

<form [action]="myAppURL" method="POST" #refreshForm></form>

Code-behind / component:

import { Component, OnInit, ViewChild } from '@angular/core';@Component({  // bla bla bla Mr. Freeman})export class FooComponent {  @ViewChild('refreshForm', { static: false }) refreshForm;  forceReload() {    this.refreshForm.nativeElement.submit();  }}

I guess this can be also done in a more non-hacky way. I am investigating... (HttpClient, maybe?)