Performance: Feature modules for organization
MEDIUM IMPACT
This affects initial page load speed and bundle size by splitting code into smaller chunks loaded on demand.
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: 'feature', loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule) } ]) ], bootstrap: [AppComponent] }) export class AppModule {}
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { FeatureComponent } from './feature/feature.component'; @NgModule({ declarations: [AppComponent, FeatureComponent], imports: [BrowserModule], bootstrap: [AppComponent] }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single large module | Many nodes loaded upfront | Multiple reflows during initial render | High paint cost due to large DOM | [X] Bad |
| Feature modules with lazy loading | Fewer nodes initially | Single reflow on initial render | Lower paint cost initially | [OK] Good |