Performance: Lazy loading routes and modules
HIGH IMPACT
This affects the initial page load speed by deferring loading of code until needed, improving time to interactive.
const routes: Routes = [ { path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule) }, { path: 'settings', loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule) }, { path: 'profile', loadChildren: () => import('./profile/profile.module').then(m => m.ProfileModule) } ];
const routes: Routes = [ { path: 'dashboard', component: DashboardComponent }, { path: 'settings', component: SettingsComponent }, { path: 'profile', component: ProfileComponent } ];
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading all routes | N/A | N/A | High initial paint cost due to large bundle | [X] Bad |
| Lazy loading routes with loadChildren | N/A | N/A | Lower initial paint cost, deferred loading | [OK] Good |