本文介绍了为什么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     

推荐答案

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

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

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

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

09-21 12:54