Performance: Lazy loading components
HIGH IMPACT
This affects the initial page load speed by deferring component loading until needed, reducing the amount of JavaScript parsed and executed upfront.
import { defineAsyncComponent } from 'vue'; export default { components: { LargeComponent: defineAsyncComponent(() => import('./LargeComponent.vue')) } };
import LargeComponent from './LargeComponent.vue'; export default { components: { LargeComponent } };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading full component | High (all nodes created upfront) | Multiple reflows during initial render | High paint cost due to large DOM | [X] Bad |
| Lazy loading with defineAsyncComponent | Lower (nodes created on demand) | Single reflow when component loads | Lower paint cost as DOM grows gradually | [OK] Good |