Performance: Nuxt project structure
This affects the initial page load speed and rendering performance by organizing how components, pages, and assets are loaded and rendered.
pages/
index.vue
about.vue
components/
Header.vue
Footer.vue
BigComponent.vue
// Use automatic component import or lazy load BigComponent only where neededpages/
index.vue
about.vue
components/
Header.vue
Footer.vue
BigComponent.vue
// All components imported globally in nuxt.config.js| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global import of all components | Low | Low | High due to large JS bundle | [X] Bad |
| Lazy loading components per page | Low | Low | Low due to smaller JS bundles | [OK] Good |
| Static assets in assets folder referenced relatively | N/A | N/A | Blocks paint until loaded | [!] OK |
| Static assets in public folder with caching | N/A | N/A | Non-blocking paint with caching | [OK] Good |
pages folder to create routes automatically from the files inside it.components holds reusable UI parts, layouts define page wrappers, and plugins add extra functionality, but none auto-generate routes.pages folder -> Option Alayouts/ folder to wrap pages.layouts/ folder and export a Vue component -> Option Blayouts/default.vue
pages/index.vue
pages/about.vue
/about?/about loads pages/about.vue automatically as a route.layouts/default.vue layout unless specified otherwise.about.vue page is shown wrapped by default.vue layout -> Option Dpages/contact.vue but visiting /contact shows a 404 error. What is the most likely cause?pages/ folder.contact.vue is inside components/, it won't create a route, causing 404 on /contact.contact.vue file is inside components/ folder instead of pages/ -> Option Clayouts/ folder, each as a Vue component.definePageMeta in each page to specify which layout to use, e.g., layout: 'admin' or layout: 'public'.layouts/public.vue and layouts/admin.vue, then specify layout in each page's definePageMeta -> Option APass the test and this pattern moves unknown