Performance: Module lazy loading preview
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 |
AdminModule located at ./admin/admin.module.ts in Angular routing?loadChildren as a function returning a promise.{ path: 'shop', loadChildren: () => import('./shop/shop.module').then(m => m.ShopModule) }/shop for the first time?{ path: 'dashboard', loadChildren: './dashboard/dashboard.module#DashboardModule' }ProfileModule only when the user navigates to /profile. The module file is at ./profile/profile.module.ts. Which of the following route configurations correctly implements this with Angular 17+ standards and ensures accessibility and performance?loadChildren as a function returning a promise with dynamic import and then to access the module class.Pass the test and this pattern moves unknown