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
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.
I recommend you that if the timeout or http call is not essential to render the webpage, avoid the call on the server side.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With