Performance: Inline vs external templates
MEDIUM IMPACT
This affects the initial page load speed and bundle size by determining how Angular loads and parses component templates.
import { Component } from '@angular/core'; @Component({ selector: 'app-example', templateUrl: './example.component.html' }) export class ExampleComponent {}
import { Component } from '@angular/core'; @Component({ selector: 'app-example', template: `<div><h1>Title</h1><p>Content here</p></div>` }) export class ExampleComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline template | Same DOM nodes | Same reflows | Same paint cost | [X] Bad (larger JS bundle delays rendering) |
| External template | Same DOM nodes | Same reflows | Same paint cost | [OK] Good (smaller JS bundle, faster initial load) |