Performance: Project structure
Project structure affects how quickly the browser can load and render the app by influencing code splitting and lazy loading.
src/
App.svelte
components/
Header.svelte
Footer.svelte
routes/
+page.svelte (Home)
about/
+page.svelte
contact/
+page.svelte
// Use SvelteKit file-based routing with dynamic imports for lazy loading routessrc/
App.svelte
components/
Header.svelte
Footer.svelte
routes/
Home.svelte
About.svelte
Contact.svelte
// All components imported eagerly in App.svelte| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Monolithic project with eager imports | Low (few nodes initially) | Low (few layout changes) | High (large JS bundle delays paint) | [X] Bad |
| Modular project with lazy-loaded routes | Low (few nodes initially) | Low (few layout changes) | Low (small JS bundle, faster paint) | [OK] Good |
src/lib is designed for reusable components and utilities.src/routes holds pages, public/assets is for static files, and static/components is not a standard folder.src/lib -> Option Csrc/lib [OK]src/routes is the folder where page components live.src/lib is for reusable components, public/pages and src/pages are not standard folders for pages.src/routes -> Option Dproject/ āā public/ ā āā logo.png āā src/ ā āā lib/ ā ā āā Button.svelte ā āā routes/ ā āā index.svelte
Button.svelte component to use it on the homepage?src/routes/index.svelte is one level deeper than src/lib/Button.svelte, so import path is ../lib/Button.svelte.../../public/logo.png is for static assets, not components; ./Button.svelte assumes Button is in routes folder; public/Button.svelte is incorrect location.src/lib/images and tried to use it in your SvelteKit page, but it doesn't load in the browser. What is the most likely reason?public folder, so files in src/lib/images are not accessible directly.src/routes, renaming to .svelte is incorrect, and file size doesn't prevent loading if path is correct.src/routes.src/lib/components.public/assets.public/assets to be served correctly.src/lib/components, and pages go inside src/routes.project/ āā public/ ā āā assets/ ā āā images/ ā āā fonts/ āā src/ ā āā lib/ ā ā āā components/ ā ā āā Button.svelte ā āā routes/ ā āā index.sveltematches all requirements exactly; other options place assets or components incorrectly.
project/ āā public/ ā āā assets/ ā āā images/ ā āā fonts/ āā src/ ā āā lib/ ā ā āā components/ ā ā āā Button.svelte ā āā routes/ ā āā index.svelte[OK]
Pass the test and this pattern moves unknown