In very rare circumstances, you might want to delay the loading of your Angular application. In this article, I’ll show you how you can do it.

Warning: Don’t do this lightly. Carefully evaluate if you really need to do this, as it can have a devastating effect on user experience!

Angular module import side-effects

In my  previous article, I’ve briefly explained the Angular application bootstrap process. One thing that I mentioned there is that the import statements remain at runtime, and are taken care of by Webpack.

What I didn’t mention though is what happens as soon as Webpack imports an Angular module; for instance with the following line:

import { AppModule } from './app/app.module';

When you see this line, you might think that nothing much happens, apart for the AppModule to be loaded and available for use in the rest of the current module. Well actually there’s a side-effect at play here!

#programming #angular #javascript #typescript

Lazy Loading Angular Applications
1.40 GEEK