Angular 12-16 performance optimization guidelines with NgModules, RxJS patterns, and classic template syntax (*ngIf, *ngFor). Use when maintaining or working with pre-v17 Angular codebases...
Comprehensive performance optimization guide for Angular 12-16 applications using NgModule-based architecture and RxJS-centric patterns. Contains 30+ rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
Reference these guidelines when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Change Detection | CRITICAL | change- |
| 2 | Bundle & Lazy Loading | CRITICAL | bundle- |
| 3 | RxJS Optimization | HIGH | rxjs- |
| 4 | Template Performance | HIGH | template- |
| 5 | Dependency Injection | MEDIUM-HIGH | di- |
| 6 | HTTP & Caching | MEDIUM | http- |
| 7 | Forms Optimization | MEDIUM | forms- |
| 8 | General Performance | LOW-MEDIUM | perf- |
change-rxjs-state - Use BehaviorSubject with OnPush for reactive statechange-onpush - Use OnPush change detection strategychange-detach-reattach - Detach change detector for heavy operationschange-run-outside-zone - Run non-UI code outside NgZonebundle-ngmodule - Organize code into feature NgModulesbundle-scam - Use Single Component Angular Modules patternbundle-lazy-routes - Lazy load routes with loadChildrenbundle-preload - Preload routes for perceived speedbundle-no-barrel-imports - Avoid barrel files, use direct importsrxjs-async-pipe - Use async pipe instead of manual subscriptionsrxjs-takeuntil - Use takeUntil with destroy$ Subject for cleanuprxjs-share-replay - Share observables to avoid duplicate requestsrxjs-operators - Use efficient RxJS operatorsrxjs-mapping-operators - Use correct mapping operators (switchMap vs exhaustMap)rxjs-no-nested-subscribe - Avoid nested subscriptionstemplate-trackby - Use trackBy function with *ngFortemplate-pure-pipes - Use pure pipes for expensive transformationstemplate-ng-optimized-image - Use NgOptimizedImage for image optimizationtemplate-no-function-calls - Avoid function calls in templatestemplate-virtual-scroll - Use virtual scrolling for large listsdi-provided-in-root - Use providedIn: 'root' for singleton servicesdi-injection-token - Use InjectionToken for non-class dependenciesdi-factory-providers - Use factory providers for complex initializationhttp-interceptors - Use class-based interceptors for cross-cutting concernshttp-transfer-state - Use TransferState for SSR hydrationforms-reactive - Use reactive forms instead of template-drivenforms-typed - Use typed FormGroup for type safetyperf-memory-leaks - Prevent memory leaks (timers, listeners, subscriptions)perf-web-workers - Offload heavy computation to Web Workersarch-smart-dumb-components - Use Smart/Dumb component patternRead individual rule files for detailed explanations and code examples:
rules/change-rxjs-state.md
rules/bundle-ngmodule.md
rules/rxjs-takeuntil.md
Each rule file contains:
For the complete guide with all rules expanded: AGENTS.md