Performance: Root module (AppModule) structure
MEDIUM IMPACT
This affects the initial page load speed and rendering performance by controlling how much code and how many components load at startup.
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', 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 |
|---|---|---|---|---|
| Import all feature modules in AppModule | Low (few nodes initially) | Low (initial load only) | High (delayed paint due to JS parsing) | [X] Bad |
| Lazy load feature modules via Router | Low (few nodes initially) | Low (initial load only) | Low (faster paint) | [OK] Good |