问题描述
我正在构建一个 Angular 通用应用程序,我现在拥有的只是网站的结构.我所做的一切都与教程中有关为 Angular Universal 转换我的应用程序一样.
console.log("got Request " + new Date());res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req , time: true},功能(错误,html){console.log("渲染完成" + new Date());res.send(html);});
渲染需要 3 秒半.这对我来说似乎是一个巨大的时间.同样在 Chrome TTFB 中的 DeveloperTools 是 3.5 秒.除了路由之外,该应用程序还没有做任何事情.我不希望我未来的应用程序如此缓慢.
任何人都知道这是正常现象还是有什么需要改进的地方?存在问题的 Github 存储库 https://github.com/Joniras/slow-universal-rendering-例子
设置工作区并运行 angular-universal:
npm 安装npm 运行构建:通用npm 运行服务:通用
版本:Angular CLI:1.5.0
节点:6.11.5
操作系统:win32 x64
角度:5.0.1
...动画、通用、编译器、编译器-cli、核心、表单
... http、语言服务、平台浏览器
... 平台浏览器动态,平台服务器,路由器
@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
打字稿:2.4.2
webpack: 3.8.1
express 4.16.2
我必须将样式设置为代码,否则我无法发布
您的代码 (UserService) 中存在 3000 毫秒超时
setTimeout(() => {解决(this.loggedInUser);}, 3000);
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
There is a 3000 ms timeout in your code (UserService)
setTimeout(() => {
resolve(this.loggedInUser);
}, 3000);
这篇关于为什么 Angular Universal 中的 res.render 需要这么长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!