Performance: Lazy loading standalone components
HIGH IMPACT
This affects the initial page load speed by deferring loading of components until needed, improving time to interactive.
const featureLoader = () => import('./feature.component').then(m => m.FeatureComponent); @Component({ selector: 'app-root', template: '<ng-container *ngComponentOutlet="featureLoader()"></ng-container>' }) export class AppComponent {}
import { FeatureComponent } from './feature.component'; @Component({ selector: 'app-root', template: '<app-feature></app-feature>' }) export class AppComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading standalone component | High upfront DOM nodes | Multiple reflows during initial load | High paint cost due to large bundle | [X] Bad |
| Lazy loading standalone component | DOM nodes added on demand | Single reflow when component loads | Lower paint cost initially | [OK] Good |