Angular › Performance & Lazy Loading
What is lazy loading in Angular and why is it useful for performance?
BeginnerAnswer
Lazy loading means only downloading the code for a specific feature or route when the user actually navigates to it, instead of including everything in the app's initial bundle. This makes the very first page load faster, since the browser only needs to download the code it actually needs right away.
const routes: Routes = [
{ path: 'orders', loadChildren: () => import('./orders/orders.routes') }
];
// The orders feature's code is only downloaded when a user visits the orders routeReal-world example A large admin panel only downloads the code for its rarely visited reports section the first time a user actually navigates there, thanks to lazy loading that specific feature, keeping the initial page load fast for everyone.