SvelteKit is the official application framework for Svelte, a compiler-based UI library, and it supplies everything a component library alone does not: file-based routing, server-side rendering, data loading, form handling and deployment adapters. In the field of web applications, it occupies the same role that Next.js plays for React and Nuxt plays for Vue.js, turning reusable components into a complete, deployable product.
The framework reached version 1.0 in December 2022 and version 2.0 in December 2023, and it builds on Vite for development and bundling. Its defining idea is that one codebase can render pages in three places: on the server, in the browser or at build time, with the choice made per route rather than for the whole site.
How SvelteKit structures an application
SvelteKit organizes an application through filesystem routing: every directory inside src/routes becomes a URL path, and specially named files inside it define what that path does. A directory such as src/routes/blog/[slug] creates a dynamic route whose bracketed segment becomes a parameter available to code.
The plus-sign prefix marks route files that the framework treats as entry points, while all other files remain ordinary modules. This convention separates code that may run in the browser from code that must stay on the server, which is the most important boundary in the framework.
The table below lists the route files that appear in most projects and where each one executes.
| File | Purpose | Runs on |
|---|---|---|
| +page.svelte | Page component rendered for the route | Server and browser |
| +page.js | Universal load function for page data | Server and browser |
| +page.server.js | Server load function and form actions | Server only |
| +layout.svelte | Shared wrapper for nested routes | Server and browser |
| +server.js | API endpoint answering HTTP methods | Server only |
| +error.svelte | Error page for the route subtree | Server and browser |
Beyond routes, the hooks.server.js file exposes a handle function that intercepts every request. Teams use it for authentication, session lookup and response headers, because it runs before any load function and can modify the response afterward.
Rendering modes and page options
By default, SvelteKit performs server-side rendering on the first request and then hydrates the page so that later navigation happens through client-side routing. This hybrid model gives fast first paint and indexable HTML while keeping the responsiveness of a single-page application.
Developers change this behavior with page options exported from a page or layout file. Because options cascade down the route tree, one layout can turn a whole section into a statically generated area while another section stays fully dynamic.
| Option | Effect when set | Typical use |
|---|---|---|
| prerender = true | HTML is generated once at build time | Documentation, marketing pages |
| ssr = false | Server sends an empty shell, browser renders | Dashboards that rely on browser-only APIs |
| csr = false | No JavaScript is shipped to the page | Purely static content pages |
| trailingSlash | Controls whether URLs end with a slash | Matching legacy URL structures |
Combining these options lets one project behave as an MPA, an SPA or an SSG in different places. Setting both ssr and csr to false is invalid for interactive content, so the framework expects at least one rendering path to remain enabled.
Data loading, form actions and progressive enhancement
Load functions are the standard way to fetch data for a page. A load function returns an object that the page receives as its data property, and SvelteKit runs parallel loads for nested layouts to avoid request waterfalls where possible.
A universal load in +page.js runs on the server during the first render and in the browser on later navigation, so it must not touch secrets. A server load in +page.server.js always runs on the server and can safely use database connections and private environment variables imported from $env/static/private.
Form actions handle POST requests from ordinary HTML forms. Because a native form element works without JavaScript, the page remains usable when scripts fail; adding the use:enhance directive upgrades the same form to submit without a full page reload. This approach follows the principle of progressive enhancement and reduces the amount of custom client code.
SvelteKit compared with related frameworks
SvelteKit belongs to the family of meta-frameworks that wrap a component library with routing and rendering. The differences lie mainly in the underlying UI model and in how much runtime code reaches the browser.
The following comparison summarizes the main architectural contrasts with neighboring frameworks.
| Framework | Component layer | Reactivity model | Notable trait |
|---|---|---|---|
| SvelteKit | Svelte | Compiled, no virtual DOM | Small client bundles |
| Next.js | React | Virtual DOM with hooks | React Server Components |
| Nuxt | Vue.js | Proxy-based reactivity | Auto-imported composables |
| Remix | React | Virtual DOM with hooks | Web-standard forms and loaders |
| Astro | Multiple libraries | Islands architecture | Zero JavaScript by default |
Because Svelte compiles components into direct DOM updates, SvelteKit applications often ship less framework runtime than comparable React projects. The trade-off is a smaller ecosystem of third-party components and fewer experienced developers on the hiring market.
Deployment through adapters
SvelteKit separates the build output from the hosting platform through adapters, small packages that convert the generic server build into the format a target environment expects. The default adapter-auto detects common platforms during the build.
Choosing an adapter decides whether the application runs as a long-lived Node.js process, as serverless functions, at the network edge or as plain static files.
| Adapter | Output | Fits |
|---|---|---|
| adapter-node | Standalone Node.js server | Containers and virtual machines |
| adapter-static | Static HTML and assets | Fully prerendered sites, CDN hosting |
| adapter-vercel | Serverless and edge functions | Vercel deployments |
| adapter-netlify | Netlify functions | Netlify deployments |
| adapter-cloudflare | Workers-compatible bundle | Cloudflare edge network |
Limitations and common mistakes
Most problems with SvelteKit come from misplacing code across the server-browser boundary or from assuming that a single rendering mode applies everywhere.
- Importing secrets into universal code: the framework blocks private environment modules in browser bundles, but logic copied into
+page.jscan still leak data through returned objects. - Using browser globals during SSR: accessing
windoworlocalStorageat module level fails on the server; such code belongs inonMountor behind thebrowserflag. - Prerendering dynamic pages: a prerendered route freezes its data at build time, so frequently changing content shows stale information until the next build.
- Ignoring migration effort: the move to Svelte 5 introduced runes such as
$stateand$derived, and older component patterns need gradual updating.
A plain-language summary
Svelte is a tool for building the individual pieces of a website, such as buttons, menus and forms. SvelteKit is the toolkit that assembles those pieces into a complete website, deciding which page appears at which address, where the data comes from and how the finished product is put online.
A useful comparison is a kit house. Svelte provides well-made walls and windows, while SvelteKit provides the floor plan, the plumbing and the delivery truck. The result is a fast site that works before scripts load, and it can be placed on many kinds of hosting.
An example from practice
A small regional newspaper rebuilds its website with SvelteKit. Article pages use a server load function that reads stories from the content database, and the editors configure the archive section with prerender = true, so thousands of older articles become static files served directly from a content delivery network.
The comment form on each article uses a form action with use:enhance, which means readers on slow mobile connections can still post comments even if JavaScript has not finished loading. The team deploys with adapter-node inside a container on its existing infrastructure.
After launch, the newsroom observes that article pages are noticeably lighter than in the previous React-based site, and the archive no longer places load on the database. The editors gain speed and lower hosting costs without giving up dynamic features on the current news pages.