title: angular universal app performance, APP_BOOTSTRAP_LISTENER, flicker
body: <pre><code>Angular 4.4.6
  Angular CLI 1.3.2
  Node 6.x.x
  NPM 3.10.10
  Webpack 3.4.1
  </code></pre>
  
  <p>In Angular Universal application when server view sift to client view there is flicker of screen, because all the API's which were called in server side rendering, also called in client side rendering, due to there was a flicker.</p>
  
  <p>To remove this flicker I implemented Angular Universal Transfer Module, it stores data in a Map cache (<code>private _map = new Map&lt;string, any&gt;();</code>) while in server side rendering, and transfers it to client so client does not need to call the api again and imediately have the data from cache.</p>
  
  <p>And the transfer was through this provider.</p>
  
  <pre><code>{
      provide: APP_BOOTSTRAP_LISTENER,
      useFactory: onBootstrap,
      multi: true,
      deps: [
          ApplicationRef,
          TransferState
      ]
  }
  
  export function onBootstrap(appRef: ApplicationRef, transferState: TransferState) {
      return () =&gt; {
          appRef.isStable
          .filter(stable =&gt; stable)
          .first()
          .subscribe(() =&gt; {
              transferState.inject();
          });
      };
  }
  </code></pre>
  
  <p>This way the flicker has gone, but application performace has decreased, on load testing the app, the flickered result is more faster than non-flickered app, why is that ?</p>
  
  <p>May be because in case of load testing or in case of bots hitting the website there is no browser so the cache never get cleared and it just fill the server with cache memory and server gets slow, what could be the solution for that, either create different instace for bots and real user, by identifying request at nginx level, oe there is some other thing I'm missing in angular universal.</p>