Return to site

ANGULAR INTERVIEW QUESTION: Why using lazy loading in your application ?

December 22, 2021

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.

𝐒ðĻ ðĨ𝐚ðģðē-ðĨðĻ𝐚𝐝ðĒ𝐧𝐠 ðĒðĶðĐðŦðĻðŊ𝐞𝐎 ðĐ𝐞ðŦ𝐟ðĻðŦðĶ𝐚𝐧𝐜𝐞𝐎, 𝐚𝐧𝐝 ðĒ𝐭 ðĒ𝐎 ð­ðĄðž 𝐟ðĒðŦ𝐎𝐭 𝐛𝐞𝐎𝐭 ðĐðŦ𝐚𝐜𝐭ðĒ𝐜𝐞 𝐚𝐜𝐜ðĻðŦ𝐝ðĒ𝐧𝐠 𝐭ðĻ 𝐆ðĻðĻ𝐠ðĨ𝐞 𝐭ðĻ 𝐎ðĐ𝐞𝐞𝐝 ðŪðĐ ðēðĻðŪðŦ 𝐚ðĐðĐ.