ANGULAR INTERVIEW QUESTION: Why using lazy loading in your application ?
Lazy loading is a one of the most powerful ๐ช feature to strengthen Angular application performances.
As component additions progress, the Angular app gets bigger and heavier. ๐ชจ
Then, at some point, the app takes so much time to load (3s, 4s...) that users leave it. โน๏ธ
There, lazy-loading enters the game ๐งโ๐ค by loading a module only if the user need it (when he goes to the related URL),
so if the user does not browse the URL of a module, that app does not load the module linked to that URL ๐ฆธโโ๏ธ.
๐๐๐ซ๐ ๐๐ซ๐ ๐ญ๐ก๐ ๐๐๐ฏ๐๐ง๐ญ๐๐ ๐๐ฌ ๐จ๐ ๐ฅ๐๐ณ๐ฒ-๐ฅ๐จ๐๐๐ข๐ง๐ :
๐ The initial application loading is by far faster โฉ , because you only load a module rather than all the app modules.
๐ You can load features on demand ๐ . You accelerate that way the loading time for the users going only on some parts of the app.
๐ You can add new features without slowing down the whole app (consuming network bandwidth โก only for the feature module, while a monolith app would consume wider bandwidth for all the features at the same time)
๐ This forces you to better architect ๐บ๏ธ your app, because all asynchronous routes (URL) are based on lazy-loading. You have consequently to cut โ๏ธ your app, by grouping each feature in a module.
๐๐จ ๐ฅ๐๐ณ๐ฒ-๐ฅ๐จ๐๐๐ข๐ง๐ ๐ข๐ฆ๐ฉ๐ซ๐จ๐ฏ๐๐ฌ ๐ฉ๐๐ซ๐๐จ๐ซ๐ฆ๐๐ง๐๐๐ฌ, ๐๐ง๐ ๐ข๐ญ ๐ข๐ฌ ๐ญ๐ก๐ ๐๐ข๐ซ๐ฌ๐ญ ๐๐๐ฌ๐ญ ๐ฉ๐ซ๐๐๐ญ๐ข๐๐ ๐๐๐๐จ๐ซ๐๐ข๐ง๐ ๐ญ๐จ ๐๐จ๐จ๐ ๐ฅ๐ ๐ญ๐จ ๐ฌ๐ฉ๐๐๐ ๐ฎ๐ฉ ๐ฒ๐จ๐ฎ๐ซ ๐๐ฉ๐ฉ.