7

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.

Keyul
  • 729
  • 1
  • 8
  • 20
  • open dev tools' `Performance` tab, record loading and see what it shows. – c69 Aug 06 '19 at 00:05
  • 1
    @c69 Added screenshot of performance tab. – Keyul Aug 06 '19 at 02:20
  • 2
    this is very annoying, they tell you that SSR and Angular Universal is the solution, and when you try them and experience the slowness you can't find any resources to help – Kardon63 Nov 02 '22 at 07:00

2 Answers2

4

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);
}
Pian0_M4n
  • 2,505
  • 31
  • 35
3

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.

RafaGomez
  • 31
  • 2
  • I have the same problem, but what if i have a home page that have multiple requests, and also the request would take for example 4 seconds to finish (on slow 3G), but why the loading of the website is taking 14 seconds – Kardon63 Nov 02 '22 at 06:58