How to remove white screen after window.location.reload(); in ionic 4

I want to reload the page after calling API in ionic 4.

When the app starts after the splash screen white screen is removed by adding this in config.xml

<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="SplashScreenDelay" value="30000" />
<preference name="FadeSplashScreenDuration" value="1000" />
<preference name="SplashScreen" value="screen" />
<preference name="ShowSplashScreen" value="true" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="FadeSplashScreen" value="true" />   

After login, it navigates to the tabs pages, In tab1 I check if the user is approved by an admin or not and according to that value message is shown on the screen.

In tab1 I am using ion-refresher to refresh the page and call API to check whether the user is approved or not.

For update UI of the screen on success if API I call :

window.location.reload();

But an issue is that after reloading page white screen appears for a while.

How to remove that white screen?

.html

<ion-refresher #refresherRef slot="fixed" (ionRefresh)="load($event)">
    <ion-refresher-content
    pullingIcon="arrow-dropdown"
    pullingText="Pull to refresh"
    refreshingSpinner="circles"
    refreshingText="Refreshing...">
    </ion-refresher-content>
  </ion-refresher>

  <div *ngIf="userData.userStatus == 2" class="emplty_class">
    Your request has been pending.
  </div>

  <div *ngIf="userData.userStatus == 1">
    Your request is approved.
  </div>

.ts

load(refresher) {
    if(this.userData.userStatus == "2"){
      let postData = new FormData();
      postData.append('user_id', this.userData.userId);

      this.authService.postData(postData, "is_verified_or_not.php").then((result) => {
        this.responseData = result;

        this.success = this.responseData.success;
        if (this.success == 1) {
          refresher.target.complete();
          // refresher.complete();
          let userDeatil = this.responseData.users_details;
          localStorage.setItem('userData', JSON.stringify(userDeatil));
          for (let data1 of userDeatil) {
            this.userStatus = data1.status;
            localStorage.setItem('userStatus', JSON.stringify(this.userStatus));
            console.log("userStatus" + this.userStatus);
          }
          if(this.userStatus == 1){
            window.location.reload();
          }
        } else {
          this.message = this.responseData.message;  
          refresher.target.complete();
          this.showToast(this.message);
        }
      }, (err) => {
        refresher.target.complete();
        console.log("Error", err);
      });
    } else{
      refresher.target.complete();
      console.log("User is already approved: " + this.userData.userStatus);
    }
  }

This is roughly the equivalent of a hydrogen bomb. You are asking the device to completely reload your app from scratch. Hence:

So,

Figure out a less drastic way to achieve your underlying goal that does not involve calling location.reload().

1 Like

Thanks.!
In tab1 I am using ion-refresher to refresh the page and call API to check whether the user is approved or not.

After refreshing page API is called if the user is approved then the status is changed in local storage but my UI is not changed. After closing an APP the UI is changed or if I am checking it in localhost then after refreshing that page.

My purpose for doing this is to refresh UI instant after the response

How to update UI instant after calling an API.

Can you please suggest any other way of doing this.

Apologies if this is over-parsing, but if you require the result of the response to that API call in order to display something new, you (sort of by definition) can’t do anything instantly after calling. You can’t even do anything instantly after the response comes, but I use this strategy to propagate changes across an app, which is close enough to “instant” for me. I would also suggest this post to you, discussing performance implications of using on-device storage during normal app operation (executive summary: I recommend not doing that).

1 Like

I just tested window.location.reload true within my apps logout function and it works fine also within the actual app.

The reload() function takes an optional parameter that can be set to true to force a reload from the server rather than the cache. Since window.location.reload(true) has been deprecated, changing location.reload(true) to location.reload() to resolve this issue. Also, you can use:

window.location.href = window.location.href;

There are multiple ways to Refresh/Reload a page with jQuery/JavaScript, some are:

location.replace(location.pathname)
window.location = window.location
window.self.window.self.window.window.location = window.location