SvelteKit is the application framework for Svelte: routing, server rendering, prerendering and form handling, built on Vite. EOXLABS builds web products in SvelteKit with Svelte 5 because one codebase can prerender what is the same for everyone and server-render the rest inside a Cloudflare Worker, next to the bindings that hold the data.
The current major version is SvelteKit 3. Its migration guide moves configuration out of svelte.config.js into the Vite plugin and raises the floor to Node 22.17, TypeScript 6, Svelte 5.57.1 and Vite 8. Examples below follow SvelteKit 3. SvelteKit is one of five frameworks in the EOXLABS stack.
How does EOXLABS run SvelteKit on Workers?
adapter-cloudflare builds the app for Workers Static Assets. In SvelteKit 3, Cloudflare APIs are no longer on platform: bindings, waitUntil and the rest are imported from cloudflare:workers, and wrangler types generates their TypeScript definitions. Secrets come through $app/env/private, and each can carry a schema; an invalid value stops the app from starting (environment variables).
A server route that reads from D1 and handles a cancellation form looks like this:
// src/routes/orders/[id]/+page.server.ts
import { env } from 'cloudflare:workers';
import { error, fail } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params }) => {
const order = await env.DB.prepare('SELECT id, status FROM orders WHERE id = ?')
.bind(params.id).first();
if (!order) error(404, 'Order not found');
return { order };
};
export const actions = {
cancel: async ({ params, request }) => {
const reason = (await request.formData()).get('reason');
if (typeof reason !== 'string' || reason.length > 500) return fail(400, { reason });
await env.DB.prepare('UPDATE orders SET status = ? WHERE id = ?')
.bind('cancelled', params.id).run();
return { cancelled: true };
},
} satisfies Actions;
Three details from the adapter's documentation shape the layout of every project:
- Durable Objects live in their own Worker. The adapter docs state that Durable Objects and Workflows, which require custom classes exported from the Worker, are not currently supported, so EOXLABS defines those classes in a separate Worker and binds to them.
- Headers depend on how a page is served. Cloudflare's
_headersfile only affects static asset responses. Dynamically rendered pages get their headers from thehandlehook. - No
fs. SvelteKit's docs rule outfson Workers;readfrom$app/serverfetches bundled files instead.
Why Svelte 5 runes?
Runes are compiler symbols: $state, $derived, $effect, $props, $bindable, $inspect and $host. Reactivity is explicit, so a reviewer can see which values update the UI without knowing framework conventions. Runes also work in .svelte.ts modules, so shared state such as a cart or a call timer is a plain TypeScript file with tests, not a component. The Svelte compiler turns each component into JavaScript and CSS at build time.
What should be prerendered, and what shouldn't?
The page options set the rule: a page can be prerendered only if any two users requesting it directly get the same content from the server. EOXLABS applies it route by route:
prerender = truefor marketing pages, documentation and legal text. Prerendered routes drop out of the server manifest, which makes the Worker smaller.prerender = 'auto'for routes like/blog/[slug], where popular entries are built ahead and the long tail is rendered on demand.- No prerendering for anything personalized, anything that reads
url.searchParams, and any page with form actions, since those need a server to accept thePOST.
Content Security Policy follows the same split. SvelteKit can generate the policy itself, using nonces for dynamic pages and hashes for prerendered ones. On prerendered pages it arrives as a <meta> tag, which ignores frame-ancestors, so EOXLABS sets that directive as a header on the static asset instead.
Why form actions instead of client-side fetch?
Form actions handle a POST from a plain <form>, so the form works before JavaScript loads, and when a managed browser blocks it. use:enhance then upgrades the same form to a fetch without a full reload, and fail() returns validation errors with an HTTP status. For a booking desk or a clinic's intake screen, a form that degrades to plain HTML is a reliability feature, not nostalgia.
SvelteKit's newer remote functions offer typed client-server calls, but they are still experimental and opt-in. EOXLABS keeps production paths on load functions and form actions until they are stable.
SvelteKit, Next.js or Astro?
| SvelteKit | Next.js | Astro | |
|---|---|---|---|
| Model | Full-stack Svelte framework on Vite | React framework for full-stack apps | Static HTML by default, with interactive islands |
| Path to Workers | First-party adapter-cloudflare | Cloudflare recommends vinext, which it labels beta (guide) | @astrojs/cloudflare adapter |
| Client JavaScript | Hydrates each page; csr = false ships none for that page | React, with Server Components in the App Router | None by default; each island opts in |
| Best fit at EOXLABS | Products with logins, forms and live data at the edge | Teams already invested in React and its libraries | Content-led sites with little interaction |
When not to use SvelteKit
- The site is mostly content. Astro strips client-side JavaScript by default and can still host Svelte components as islands.
- The client's team and component library are React. Rewriting working React code into Svelte rarely pays for itself; Next.js keeps the team productive.
- The app is a desktop or mobile shell. SvelteKit still works, but in SPA mode with server rendering off, as described on the Tauri page. Most of the reasons above no longer apply.
- The design depends on experimental features. Remote functions and
awaitin components can change without notice.
How the rendering split fits the wider architecture is covered in edge-native vs edge-deployed. For how EOXLABS takes a product from brief to launch, see product engineering. The language underneath is covered on the TypeScript page.