Performance: NgModule decorator and metadata
MEDIUM IMPACT
This affects the initial load time and rendering speed by controlling how Angular bundles and initializes modules and components.
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { RouterModule } from '@angular/router'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, RouterModule.forRoot([ { path: 'heavy-feature', loadChildren: () => import('./heavy-feature/heavy-feature.module').then(m => m.HeavyFeatureModule) } ])], bootstrap: [AppComponent] }) export class AppModule {}
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { HeavyFeatureModule } from './heavy-feature/heavy-feature.module'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule, HeavyFeatureModule], bootstrap: [AppComponent] }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eagerly importing large modules | No direct DOM impact | No reflows triggered by NgModule itself | Blocks initial paint due to large bundle | [X] Bad |
| Lazy loading feature modules | No direct DOM impact | No reflows triggered by NgModule itself | Speeds up initial paint by reducing bundle size | [OK] Good |