为什么Angular Universal中的res.render需要这么长时间? [英] Why is res.render in Angular Universal taking so long?

查看:70
本文介绍了为什么Angular Universal中的res.render需要这么长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Angular Universal App,现在我所拥有的只是该网站的结构.我完成了教程中有关将应用程序转换为Angular Universal的所有操作.

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);
   }   
);

渲染需要3个半秒..对我来说,这似乎是很长的时间.同样在Chrome TTFB中的DeveloperTools中为3.5秒. 而且该应用程序除了路由之外什么也不做.我不希望我的未来应用这么慢.

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.

任何人都知道这是正常现象还是需要改进的地方? 带有问题> https://github.com/Joniras/slow-universal-rendering-例子

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

设置工作区并运行通用角度:

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

版本:
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
我不得不将样式设置为代码,因为否则我将无法发布

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

推荐答案

您的代码(UserService)中存在3000毫秒的超时时间

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

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

这篇关于为什么Angular Universal中的res.render需要这么长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆