DEV Community

Cover image for Preload All Angular Bundles

Preload All Angular Bundles

John Papa on May 29, 2019

Users want fast apps. Getting your JavaScript bundles to your browser as quickly as possible and before your user needs them can make a huge and po...
Collapse
 
sevenstories profile image
Joe Wheatley

The best trade off I've found is if the modules are all locked by user role/permissions and make the preload strategy check permissions. If the user doesn't have permission it doesn't load. We have a rather large application at work, there's around 15 lazy loaded modules, but each user role will only ever have access to around 5

Collapse
 
john_papa profile image
John Papa

Thanks for sharing.

Could you combine that with CanLoad? Possibly don’t even let it get to a strategy for preloading if they don’t have permission

Maybe a combo of both.

Collapse
 
mfaghfoory profile image
Meysam Faghfouri

If we set it to preload all modules, will browser wait to load all of them? Or after showing first page they start to loading in background?

Collapse
 
john_papa profile image
John Papa

Here is a link to the docs that explains it best. angular.io/guide/router#preloading...

In short - the app loads - then it looks for modules it can preload.

Collapse
 
flignats profile image
Ray

I thought angular 8 was removing function calls in ngModule?

i.e. RouterModule.forRoot()

Collapse
 
john_papa profile image
John Papa

Do you have a reference for this?