Lazy-loading with loadChildren
AngularJS modules allow us to group together logically-related building units of the application. However, by default, they need to be available during the initial bootstrap of the application and do not allow deferred loading. This requires downloading the entire code base of the application during the initial page load that, in case of large single-page apps, can be an unacceptable performance hit.
In a perfect scenario, we would want to load only the code associated with the page the user is currently viewing or to prefetch bundled modules based on heuristics related to the user's behavior, which is beyond the scope of this book. For instance, open the application from the first step of our example, http://localhost:5555/dist/dev/ch7/step-1/ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access