Performance: File-based routing
File-based routing impacts initial page load speed and navigation responsiveness by controlling how routes are resolved and components are loaded.
const routes = { '/': () => import('./routes/Home.svelte'), '/about': () => import('./routes/About.svelte'), '/contact': () => import('./routes/Contact.svelte') }; // Components loaded only when route is visited
import Home from './routes/Home.svelte'; import About from './routes/About.svelte'; import Contact from './routes/Contact.svelte'; // All routes imported and bundled together const routes = { '/': Home, '/about': About, '/contact': Contact };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading all routes | Low (few nodes initially) | 1 reflow on load | High paint cost due to large bundle | [X] Bad |
| Lazy loading routes on demand | Low (nodes added per route) | 1 reflow per route load | Lower paint cost initially | [OK] Good |
+page.svelte file inside src/routes represent in SvelteKit?+page.svelte+page.svelte files define pages that users can visit through URLs.src/routes map directly to URL paths, so +page.svelte creates a page at that path.+page.svelte files become pages [OK]+page.svelte is just a component+page.svelte[param] to define dynamic route parameters.src/routes/user/[id] captures the id part dynamically for user profiles.+page.svelte filesrc/routes/ +page.svelte about/+page.svelte blog/[slug]/+page.svelte
blog/[slug]/+page.svelte page when visiting /blog/hello-world?blog/[slug] matches any URL starting with /blog/ followed by any value as slug./blog/hello-world matches the dynamic route [slug] with slug = 'hello-world'.src/routes/blog/[id].svelte instead of src/routes/blog/[id]/+page.svelte. What will happen when you visit /blog/123?+page.svelte inside, not files named with brackets.[id].svelte as a file breaks routing because SvelteKit expects [id] as a folder.+page.svelte [OK]/shop/electronics) and product pages (/shop/electronics/123) with a dynamic category and product ID. Which folder structure correctly implements this in SvelteKit?/shop/electronics (category) and /shop/electronics/123 (product), you need nested folders: one for [category] and inside it one for [product].+page.svelte. So src/routes/shop/[category]/+page.svelte can show category info, and src/routes/shop/[category]/[product]/+page.svelte shows product details.Pass the test and this pattern moves unknown