DEV Community

Discussion on: How To implement Lazy Loading in Angular

Collapse
 
chiangs profile image
Stephen Chiang

You can also specify what 'kind' of lazy load you want. The default is true lazy loading where the module isn't loaded until the user visits that module. Another is called prefetch where it's lazy loaded so it doesn't affect initial load of the app, but the lazy module is then loaded while the user is going through the app but not necessarily the lazy loaded module quick may provide a smoother transition between eager and lazy loaded modules.

Here's how to do it:

imports: [RouterModule.forRoot(ROUTES, 
    {preloadingStrategy: PreloadAllModules})]
})

Don't forget importing the dependency. You can specify per module by making your own version of this, there's an article on that out there. But as of right now, all or none is what comes out if the box from angular.