Why is res.render in Angular Universal taking so long?

Viewed 1966

I am building a Angular Universal App and all i have now is the Structure of the site. I did everything like in the tutorial concerning transforming my app for Angular Universal.

console.log("got Request " + new Date());
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req , time: true}, 
   function(err, html) {
      console.log("finished Rendering " + new Date());
      res.send(html);
   }   
);

The Rendering takes up 3 and a half seconds.. This seems like a huge amount of time to me. Also in the DeveloperTools in Chrome TTFB is 3,5 seconds. And the app doesnt do anything yet except routing. I dont want my future app to be so slow.

Anyone has a clue if this is normal or there is something to improve ? Github repo with Problem https://github.com/Joniras/slow-universal-rendering-example

Setting up Workspace and running angular-universal:

npm install   
npm run build:universal   
npm run serve:universal     

Versions:
Angular CLI: 1.5.0
Node: 6.11.5 OS: win32 x64 Angular: 5.0.1 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, platform-server, router @angular/cdk: 5.0.0-rc0 @angular/cli: 1.5.0 @angular/flex-layout: 2.0.0-beta.10-4905443 @angular/material: 5.0.0-rc0 @angular-devkit/build-optimizer: 0.0.33 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.35 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.3 typescript: 2.4.2 webpack: 3.8.1 express 4.16.2
i had to style as code because otherwise i couldnt post

1 Answers

There is a 3000 ms timeout in your code (UserService)

setTimeout(() => {
          resolve(this.loggedInUser);
        }, 3000);
Related