Performance: Standalone pipes and directives
MEDIUM IMPACT
This concept affects the initial page load speed and bundle size by allowing Angular to load only the necessary pipes and directives without extra module overhead.
import { Component } from '@angular/core'; import { MyPipe } from './my-pipe'; @Component({ selector: 'app-example', template: '{{ value | myPipe }}', standalone: true, imports: [MyPipe] }) export class ExampleComponent {}
import { Component, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MyPipe } from './my-pipe'; @NgModule({ declarations: [MyPipe], exports: [MyPipe], imports: [CommonModule] }) export class SharedModule {} @Component({ selector: 'app-example', template: '{{ value | myPipe }}', standalone: true, imports: [SharedModule] }) export class ExampleComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| NgModule imports for pipes/directives | More nodes and directives processed | Multiple reflows due to style recalculations | Higher paint cost from complex styles | [X] Bad |
| Standalone pipes/directives imports | Minimal nodes processed | Single reflow | Lower paint cost | [OK] Good |