angular-cliangular5angular-components

angular 5 lazy loading vs dynamic loading


Can somebody explain the difference between lazy loading modules and dynamic component loading in angular 5? I have some hard time to figure out when what to use. Can you provide a use case for each so I can better understand them? I am pretty new to angular 5... I know that lazy loading is about modules and dynamic components loading is about components.


Solution

  • With lazy loaded modules the browser will only load features when the user navigates to their routes for the first time. When you add components directly to your routes they will be loaded regardless if you are in any particular route, so in terms of performance and initial bundle size it is always good to have features lazy loaded.

    Reference: https://alligator.io/angular/lazy-loading/