简体   繁体   English

Angular Universal TTFB 很慢

[英]Angular Universal TTFB is very slow

When I run my application with angular universal, I am seeing huge difference in TTFB.当我使用 angular Universal 运行我的应用程序时,我发现 TTFB 存在巨大差异。 ssr is taking more time than normal angular command. ssr 比正常的角度命令花费更多的时间。 How to improve TTFB with angular universal server side rendering?如何使用角度通用服务器端渲染改进 TTFB?

npm run serve:ssr

在此处输入图片说明

Performance tab:性能选项卡: 在此处输入图片说明

ng serve

在此处输入图片说明

Looked into many sites but didn't found any relevant solution on internet till yet.查看了许多网站,但直到现在还没有在互联网上找到任何相关的解决方案。

It seems that you have a setTimeout or an http call that takes too much time to finish and angular universal does not serve the webpage until all the calls are finished.似乎您有一个 setTimeout 或 http 调用需要花费太多时间才能完成,并且在所有调用完成之前,angular Universal 不会为网页提供服务。

I recommend you that if the timeout or http call is not essential to render the webpage, avoid the call on the server side.我建议您,如果超时或 http 调用对于呈现网页不是必需的,请避免在服务器端调用。

I had the same problem and I fixed it by removing all setTimeout and setInterval我遇到了同样的问题,我通过删除所有setTimeoutsetInterval解决它

If you need to use timeouts you can use this function instead of the regular setTimeout如果你需要使用超时,你可以使用这个函数而不是常规的setTimeout

export function setTimeout$(cb: () => void, timer: number) {
  of(true).pipe(debounceTime(timer), first()).subscribe(cb);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM