1

I have a pretty good idea about loading an external config file for an Angular app, but I have the following question: does the APP_INITIALIZER provided loading function get executed on the client side, after the AppModule had been delivered to the browser, or on the server side, before the delivery happens?

And if it happens on the client side, doesn't this entail an extra HTTP call to the config file before the application actually starts?

Sammy
  • 3,395
  • 7
  • 49
  • 95
  • Thank you, that's what I thought. How mundane (or negligible) would you say the extra HTTP call to my JSON configuration file would be in your opinion? – Sammy Nov 20 '17 at 13:12
  • 1
    That probably depends mostly on the on the network connection delay. I'd try hard to avoid any request, especially if you expect it to run on mobile. But if there are no good alternatives, I'd just use `APP_INITIALIZER`. – Günter Zöchbauer Nov 20 '17 at 13:15
  • I hear you, and yet as you say, I know of no other way to better initialize configuration externally, independently of the building process. Ideally the config files would already reside on the server upon which the build is being deployed. – Sammy Nov 20 '17 at 13:17
  • 1
    Then go for it and check the profiling tab in the browser devtools to see the actual delay the request causes for your application and if it matters. Otherwise might just be a case of premature optimization ;-) – Günter Zöchbauer Nov 20 '17 at 13:18

1 Answers1

1

If you are not using server-side rendering everything Angular related is only executed in the browser, except perhaps things that are executed at build time before you deploy your Angular application to the server, but APP_INITIALIZER is executed in the browser.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567