Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Universal TTFB is very slow

When I run my application with angular universal, I am seeing huge difference in TTFB. ssr is taking more time than normal angular command. How to improve TTFB with angular universal server side rendering?

npm run serve:ssr

enter image description here

Performance tab: enter image description here

ng serve

enter image description here

Looked into many sites but didn't found any relevant solution on internet till yet.

like image 974
Keyul Avatar asked Aug 06 '19 00:08

Keyul


2 Answers

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.

I recommend you that if the timeout or http call is not essential to render the webpage, avoid the call on the server side.

like image 135
RafaGomez Avatar answered Sep 23 '22 03:09

RafaGomez


I had the same problem and I fixed it by removing all setTimeout and setInterval

If you need to use timeouts you can use this function instead of the regular setTimeout

export function setTimeout$(cb: () => void, timer: number) {
  of(true).pipe(debounceTime(timer), first()).subscribe(cb);
}
like image 24
Pian0_M4n Avatar answered Sep 23 '22 03:09

Pian0_M4n