What is lazy loading of routes?
Lazy loading of routes is a way to load parts of the application only when they are actually needed, instead of loading everything at startup.
Why it's needed:
- Reduces the initial weight of the application
- Speeds up the first load
- Makes large projects more flexible and scalable
How it works:
- You have an
AdminModulethat not every user needs right away. - Instead of a direct import, you point to it from the routing config:
ts
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)
}- When the user navigates to
/admin, Angular lazily loads the module and its components.
Summary: Lazy loading is deferred, on-demand loading that helps avoid pulling in the whole project at startup.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.