Performance: Why modules organize applications
MEDIUM IMPACT
Modules affect initial load time and runtime code execution by controlling how code is split and loaded in Angular apps.
const routes: Routes = [ { path: 'feature', loadChildren: () => import('./feature/feature.module').then(m => m.FeatureModule) } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], bootstrap: [AppComponent] }) export class AppModule {}
import { ComponentA } from './component-a'; import { ComponentB } from './component-b'; @NgModule({ declarations: [ComponentA, ComponentB], imports: [], bootstrap: [ComponentA] }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading all modules | N/A | N/A | High due to large JS bundle blocking rendering | [X] Bad |
| Lazy loading feature modules | N/A | N/A | Lower initial paint cost due to smaller bundles | [OK] Good |