Performance: Component registration (global vs local)
MEDIUM IMPACT
This affects initial page load speed and runtime rendering performance by controlling how many components are loaded and parsed upfront versus on demand.
import { createApp } from 'vue'; import App from './App.vue'; const app = createApp(App); // Register locally inside component that uses it (e.g. in App.vue): // import MyButton from './MyButton.vue' // export default { // components: { MyButton } // } app.mount('#app');
import { createApp } from 'vue'; import MyButton from './MyButton.vue'; import App from './App.vue'; const app = createApp(App); app.component('MyButton', MyButton); // global registration app.mount('#app');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global registration | All components parsed upfront | Multiple reflows if many components render | Higher paint cost due to larger DOM | [X] Bad |
| Local registration | Only used components parsed | Fewer reflows as fewer components render initially | Lower paint cost with smaller DOM | [OK] Good |