Reputation: 9235
For context:
I have Angular 5 app whose startup cycle involves:
I decided to go through the whole startup cycle using debugger step by step and realized that Angular triggers change detection on many processes during startup cycle.
Now i wonder (question): considering all of the activity before app inits is just to prepare data to be used by the app - should i detach change detection during app init cycle and reattach change detection once init is over and then trigger it?
Basically trying to understand if this is going to save loading time and processing or is that a bad idea?
Update: since I went through a lot of articles re this topic I realized additional facts that might be altering the way I should ask this question.
Change Detection relates to "views" - if there are not templates and bindings in those - it might be not even worth to try to optimize this
For more or less serious app it is a common practice to switch to onPush CD strategy, which also can help eliminate the need for additional improvements here.
Last thing - I will still try the following experiment later today:
Upvotes: 0
Views: 302
Reputation: 65
If you want to initialize data for application or check Authentication/Authorization.
For this purpose you can use Routing guard such as canActivate or Resolve on the "/" base URL. Use "rxjs/operator/take" to wait for first response before route initiate the component.
Move all you loading logic to guard.
Upvotes: 1