Performance: Lazy loading components
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 |
defineAsyncComponent?const AsyncComp = defineAsyncComponent(() => import('./AsyncComp.vue'))
export default {
components: { AsyncComp },
template: ``
}const AsyncComp = defineAsyncComponent(import('./AsyncComp.vue'))CompA and CompB, but only show CompB after CompA finishes loading and rendering. Which approach correctly achieves this?CompB to appear only after CompA fully loads and renders.CompA in Suspense to handle loading, then show CompB conditionally after CompA is ready.Pass the test and this pattern moves unknown