SvelteKit
The official Svelte application framework with file-based routing, load functions, form actions and flexible rendering.
Intermediate · about 8 hours · difficulty 3/5
Learn first: CSR, SSR, SSG, ISR and Streaming, Svelte
SvelteKit is the full-stack framework for Svelte. It combines Svelte's small, fast components with routing, server rendering, data loading and deployment adapters.
Core concepts
- Routing from
src/routes:+page.sveltefor a page,+layout.sveltefor shared layouts,[param]folders for dynamic segments and+error.sveltefor errors. - Load functions:
+page.ts(runs on server and client) or+page.server.ts(server only, safe for secrets and databases) return data that the page receives as a prop. - Form actions in
+page.server.tshandle<form method="POST">submissions, withuse:enhancefor progressive enhancement. - API routes with
+server.tsfor JSON endpoints. - Hooks (
hooks.server.ts) for auth, logging and request handling. - Rendering options per route: SSR, prerendering (
export const prerender = true) or CSR only. - Adapters deploy to Node, Vercel, Netlify, Cloudflare or static hosts.
Pitfalls
Putting secrets in universal +page.ts loads (they also run in the browser), forgetting validation in form actions, and mixing Svelte 4 and Svelte 5 syntax from older tutorials.
Good enough to move on
You can build a SvelteKit app with layouts, server load functions, form actions with validation and progressive enhancement, and deploy it with an adapter.
Key concepts
- Routes, pages and layouts
- Universal vs server load functions
- Form actions and use:enhance
- API routes with +server.ts
- Hooks
- Prerendering and rendering options
- Deployment adapters
Other options for this step
- Next.js: The leading React framework: App Router, layouts, Server Components, data fetching and caching, Server Actions and middleware.
- React Router Framework Mode (Remix): Web-standards-first full-stack React with loaders, actions and nested routes; the evolution of Remix.
- Nuxt: The full-stack framework for Vue: file-based routing, SSR and SSG, auto-imports, data fetching and server routes.
- Astro: A content-first framework that ships zero JavaScript by default and hydrates interactive islands built with any UI library.
Mini project
Build a link-sharing app in SvelteKit with server load functions reading from a database, form actions to add and upvote links with validation, a hooks-based session check and deployment with an adapter.
Check yourself
Why should a database query live in +page.server.ts rather than +page.ts?
Free resources
- SvelteKit Documentation (Svelte)
- SvelteKit Tutorial (Svelte)