Performance: Module lazy loading preview
HIGH IMPACT
This affects the initial page load speed by deferring loading of feature modules until needed, reducing the amount of code loaded upfront.
const routes = [ { path: 'feature', loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule) } ]; @NgModule({ imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })], exports: [RouterModule] }) export class AppRoutingModule {}
import { FeatureModule } from './feature/feature.module'; const routes = [ { path: 'feature', component: FeatureComponent } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager module loading | Low (no extra DOM nodes) | 0 | High (large JS blocks delay paint) | [X] Bad |
| Lazy module loading | Low (no extra DOM nodes) | 0 | Low (smaller initial JS, faster paint) | [OK] Good |