2

At the start of my application(after login, each reload), i would like to load(API-request) a logo in the background which im going to need later on. Is there a way to let it load in the background without it affecting the performance?

I tried to execute the request inside the app.component.ts because thats the one class which gets executed right at the start:

export class AppComponent {
  constructor(private oAuthService: OAuthService, private logoService: LogoService) {

    // a lot of configs...

    this.oAuthService.configure(config);
    this.oAuthService.setStorage(sessionStorage);
    this.oAuthService.tryLogin({}).then();

    this.logoService.getLogo().subscribe(logo => {
      // save logo somewhere
    }
  }
}

But this ended up slowing down the first loading process. Why is that? Isnt the request just happening asynchronously in the background?

M.Dietz
  • 900
  • 10
  • 29
  • 1
    How did you measure, that it is slower? with isStable? – Stefan Dec 09 '19 at 14:30
  • can this help you? https://stackoverflow.com/questions/35763730/difference-between-constructor-and-ngoninit – Ashot Aleqsanyan Dec 09 '19 at 14:34
  • @Stefan I didnt measure it, its like half a second slower so its easy to see without having to measure. But i think i described the problem wrong. What takes longer isnt the time till the first component is loaded, its the time till the api-requests the first loaded component does are finished. And thats probably because of the picture being downloaded in the background which utilizes the bandwidth? – M.Dietz Dec 09 '19 at 14:50

0 Answers0