# SvelteKit

SvelteKit scores 23 of 28 points on 14 speed features: 13/14 on first-paint levers and 10/14 on other features. Rank 4 of 23, tied with Qwik City. Labels: 10 1st-party, 0 Experimental, 3 Third-party, 1 Manual.

- Version checked: @sveltejs/kit ^3.0.1 (lockfile 3.0.1; latest 3.4.0), Vite ^8.1.5 (lockfile 8.3.0) (optimized branch; Vercel ISR adapter; Unpic + IPX; Fontsource)
- Performance guide: [Performance • SvelteKit Docs](https://svelte.dev/docs/kit/performance)
- Issue tracker: https://github.com/sveltejs/kit/issues
- Books demo port: [svelte-books](https://github.com/MaxwellCohen/svelte-books)

## Summary

| Feature | Group | Label | Points |
| --- | --- | --- | --- |
| [Production CSS inlining](https://framework-compare.vercel.app/features/css-inlining.md) | First-paint levers | 1st-party | 2 |
| [Font optimization](https://framework-compare.vercel.app/features/font-optimization.md) | First-paint levers | Third-party | 1 |
| [Image pipeline](https://framework-compare.vercel.app/features/image-pipeline.md) | First-paint levers | 1st-party | 2 |
| [Data/HTML caching](https://framework-compare.vercel.app/features/caching.md) | First-paint levers | 1st-party | 2 |
| [Route prefetching](https://framework-compare.vercel.app/features/route-prefetching.md) | First-paint levers | 1st-party | 2 |
| [Streaming SSR](https://framework-compare.vercel.app/features/streaming-ssr.md) | First-paint levers | 1st-party | 2 |
| [Early Hints / preload headers](https://framework-compare.vercel.app/features/early-hints.md) | First-paint levers | 1st-party | 2 |
| [Islands / partial hydration / lazy slices](https://framework-compare.vercel.app/features/islands.md) | Other features | Manual | 0 |
| [Per-route render modes](https://framework-compare.vercel.app/features/render-modes.md) | Other features | 1st-party | 2 |
| [Fine-grained client reactivity](https://framework-compare.vercel.app/features/reactivity.md) | Other features | 1st-party | 2 |
| [Built-in bundle analysis](https://framework-compare.vercel.app/features/bundle-analysis.md) | Other features | Third-party | 1 |
| [Third-party script strategies](https://framework-compare.vercel.app/features/third-party-scripts.md) | Other features | Third-party | 1 |
| [Portable multi-host deployment](https://framework-compare.vercel.app/features/multi-host-deployment.md) | Other features | 1st-party | 2 |
| [Service worker / offline support](https://framework-compare.vercel.app/features/service-worker.md) | Other features | 1st-party | 2 |

## First-paint levers

### Production CSS inlining

Label: **1st-party** (2 of 2 points).

Set [`inlineStyleThreshold`](https://svelte.dev/docs/kit/@sveltejs-kit-vite) high enough (e.g. `Number.POSITIVE_INFINITY`; the docs define it as the max CSS file length in UTF-16 code units) in `vite.config.ts`. One line, but you have to know it exists.

```ts
sveltekit({
  inlineStyleThreshold: Number.POSITIVE_INFINITY,
})
```

*From this repo's `svelte-books/vite.config.ts` (`optimized` branch).*

### Font optimization

Label: **Third-party** (1 of 2 points).

Import `@fontsource-variable/geist` ([Fontsource](https://fontsource.org)). SvelteKit has no first-party font module and [does not preload fonts by default](https://svelte.dev/docs/kit/performance); the `handle` hook's `resolve(..., { preload })` filter can add font preloads (not used here), so the font is discovered from the inlined stylesheet.

```css
@import "@fontsource-variable/geist";
```

*From this repo's `svelte-books/src/routes/layout.css` (`optimized` branch).*

### Image pipeline

Label: **1st-party** (2 of 2 points).

The framework offers [`@sveltejs/enhanced-img`](https://svelte.dev/docs/kit/images), a build-time plugin that only optimizes image files present at build. For remote images such as this port's covers the same page points to a CDN and names the community `@unpic/svelte`, so this port uses Unpic transforms plus an `ipx` handler (`src/lib/server/ipx-handler.ts`), disabled on Cloudflare. [`adapter-vercel`](https://svelte.dev/docs/kit/adapter-vercel) also has an `images` option (not used here). To use the first-party route for local files:

```ts
enhancedImages(), // must come before the SvelteKit plugin
```

```svelte
<enhanced:img src="./path/to/your/image.jpg" alt="An alt text" />
```

*Adapted from [the images docs](https://svelte.dev/docs/kit/images).*

Art direction with `<picture>` (1st-party, not scored):

[`enhanced:img`](https://svelte.dev/docs/kit/images) (local files only) is replaced at build time by an `<img>` wrapped in a `<picture>` with multiple formats and sizes; that is modern formats, not breakpoint art direction. Setup is the plugin line shown in [section 3](https://framework-compare.vercel.app/features/image-pipeline):

```svelte
<enhanced:img src="./path/to/your/image.jpg" alt="An alt text" />
```

*From [the images docs](https://svelte.dev/docs/kit/images).*

Gotchas:

- Sharp does not run on Cloudflare Workers, so this port switches image optimization off there.
- `@sveltejs/enhanced-img` only processes local images at build time; remote covers need a runtime optimizer.

### Data/HTML caching

Label: **1st-party** (2 of 2 points).

Use [`adapter-vercel`](https://svelte.dev/docs/kit/adapter-vercel)'s per-route `isr` option, exported as `config` from a route, as done in `src/lib/server/page-isr.ts`. SvelteKit also has first-party, host-independent pieces: [`setHeaders`](https://svelte.dev/docs/kit/load) in `load` for `cache-control` (this port sets it in `src/routes/+layout.server.ts`) and per-route [`prerender`](https://svelte.dev/docs/kit/page-options). The experimental [remote functions](https://svelte.dev/docs/kit/remote-functions) only dedupe a `query` within one request (and share it on the client while it is in use); their `prerender` variant stores build-time data. This port turns on the `remoteFunctions` flag but defines no remote functions. A cross-request data cache on other hosts is manual: `src/lib/server/catalog-cache.ts` with Vercel Cache, Netlify Blobs, and the Workers KV/Cache API paths.

```ts
export const catalogIsrConfig = {
  isr: { expiration: CATALOG_CACHE_REVALIDATE_SECONDS, allowQuery: ['page', 'search'] }
} satisfies Config;
```

```ts
// src/routes/+page.server.ts
export const config = catalogIsrConfig;
```

*From this repo's `svelte-books/src/lib/server/page-isr.ts` and `src/routes/+page.server.ts` (`optimized` branch; `allowQuery` shortened and spread removed).*

### Route prefetching

Label: **1st-party** (2 of 2 points).

Set [`data-sveltekit-preload-data="hover"`](https://svelte.dev/docs/kit/link-options). This repo's `FastLink` wrapper maps a `preload` prop to that attribute per link (`'hover'` or `'off'`); the pagination and sidebar links pass it explicitly and book cards pass `preload={eagerPrefetch}`. The starter template already sets the attribute on `<body>`, and JS/CSS are preloaded automatically ([performance](https://svelte.dev/docs/kit/performance)).

```html
<body data-sveltekit-preload-data="hover">
```

*From this repo's `svelte-books/src/app.html` (`optimized` branch; class attribute omitted).*

Gotchas:

- Needs the `data-sveltekit-preload-data` attribute somewhere (the starter template adds it).

### Streaming SSR

Label: **1st-party** (2 of 2 points).

Return a promise from a server `load` without awaiting it ([streaming with promises](https://svelte.dev/docs/kit/load)). The page renders with the awaited data, and each promise is streamed to the browser when it resolves; `{#await}` shows the placeholder.

```js
export async function load({ params }) {
  return {
    comments: loadComments(params.slug),
    post: await loadPost(params.slug)
  };
}
```

*From [the SvelteKit `load` docs](https://svelte.dev/docs/kit/load) (comments omitted).*

### Early Hints / preload headers

Label: **1st-party** (2 of 2 points).

Set [`output.linkHeaderPreload: true`](https://svelte.dev/docs/kit/@sveltejs-kit-vite#output) (SvelteKit 3.0+, default `false`). Pages that are not prerendered then preload their JS and CSS through the HTTP `Link` header instead of `<link>` elements. SvelteKit does not document sending a 103 itself.

```ts
sveltekit({
  output: {
    linkHeaderPreload: true,
  },
})
```

*Adapted from [the `output` config docs](https://svelte.dev/docs/kit/@sveltejs-kit-vite#output); the option sits next to `inlineStyleThreshold` in this repo's `svelte-books/vite.config.ts`, which does not set it.*

## Other features

### Islands / partial hydration / lazy slices

Label: **Manual** (0 of 2 points).

No first-party islands are documented; all interactive components hydrate, though disabling hydration for a whole route is possible ([page options](https://svelte.dev/docs/kit/page-options)):

```ts
export const csr = false;
```

*From [the page options docs](https://svelte.dev/docs/kit/page-options).*

### Per-route render modes

Label: **1st-party** (2 of 2 points).

Export `prerender`, `ssr`, and `csr` per route ([page options](https://svelte.dev/docs/kit/page-options)).

```ts
export const prerender = true;
export const ssr = false;
export const csr = false;
```

*From [the page options docs](https://svelte.dev/docs/kit/page-options) (each is a separate option; combine as needed).*

### Fine-grained client reactivity

Label: **1st-party** (2 of 2 points).

[Runes](https://svelte.dev/docs/svelte/what-are-runes) (`$state`, `$derived`, `$effect`). Dependencies are picked up at runtime from whatever a [`$derived`](https://svelte.dev/docs/svelte/$derived) or `$effect` reads, not by compile-time analysis, and `$state` proxies trigger granular updates. Nothing to enable.

```ts
let isOpen = $state(false);
```

*From this repo's `svelte-books/src/lib/features/book/components/MobileBookSidebar.svelte` (`optimized` branch).*

### Built-in bundle analysis

Label: **Third-party** (1 of 2 points).

No built-in analyzer; the [performance docs](https://svelte.dev/docs/kit/performance) suggest [rollup-plugin-visualizer](https://github.com/btd/rollup-plugin-visualizer) in `vite.config.ts`. Not configured in this port. No config snippet for it was found in the docs.

Example of building it yourself:

Add `rollup-plugin-visualizer` after `sveltekit()` in the Vite config. `vite build` then writes a treemap of the bundle to `stats.html`.

```ts
// vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite';
import tailwindcss from '@tailwindcss/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [
		tailwindcss(),
		sveltekit({ /* … */ }),
		visualizer({ filename: 'stats.html', gzipSize: true })
	]
});
```

Source: [SvelteKit: Performance](https://svelte.dev/docs/kit/performance)

### Third-party script strategies

Label: **Third-party** (1 of 2 points).

No first-party script primitive is documented; the [performance docs](https://svelte.dev/docs/kit/performance) point to [Partytown's SvelteKit integration](https://partytown.qwik.dev/sveltekit/) (community package `@qwik.dev/partytown`) for running third-party scripts in a web worker. Otherwise add the tag in [`app.html`](https://svelte.dev/docs/kit/project-structure) or a component and manage ordering yourself. Not configured in this port.

Example of building it yourself:

Install `@qwik.dev/partytown`, add its Vite plugin, and print the Partytown snippet in the root layout. Scripts tagged `type="text/partytown"` then run in a web worker instead of the main thread.

```js
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { partytownVite } from '@qwik.dev/partytown/utils';

export default { plugins: [sveltekit(), partytownVite()] };
```

```svelte
<!-- src/routes/+layout.svelte -->
<script>
	import { partytownSnippet } from '@qwik.dev/partytown/integration';
</script>

<svelte:head>
	<script>
		// Forward the necessary functions to the web worker layer
		partytown = { forward: ['dataLayer.push'] };
	</script>
	{@html '<script>' + partytownSnippet() + '</script>'}
	<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
</svelte:head>
```

Source: [Partytown: SvelteKit](https://partytown.qwik.dev/sveltekit/)

### Portable multi-host deployment

Label: **1st-party** (2 of 2 points).

Pick an [`adapter`](https://svelte.dev/docs/kit/adapters) for Node, Vercel, Netlify, Cloudflare, or static output.

```ts
const adapter = isCloudflare
  ? cloudflareAdapter
  : process.env.NETLIFY
    ? netlifyAdapter
    : vercelAdapter;
// ...
sveltekit({ adapter: adapter() })
```

*From this repo's `svelte-books/vite.config.ts` (`optimized` branch; other options omitted).*

### Service worker / offline support

Label: **1st-party** (2 of 2 points).

Create `src/service-worker.js` (or `src/service-worker/index.ts`). SvelteKit bundles it and registers it automatically, and the [`$service-worker`](https://svelte.dev/docs/kit/service-workers) module gives it the built files, the static files, and a version string.

```js
import { build, files, version } from '$service-worker';

const CACHE = `cache-${version}`;
const ASSETS = [...build, ...files];
```

*Adapted from [the SvelteKit service workers docs](https://svelte.dev/docs/kit/service-workers) (the `install`, `activate`, and `fetch` handlers that use these are omitted).*

## Other performance features

`bundleStrategy` ([`output` config](https://svelte.dev/docs/kit/@sveltejs-kit-vite#output)).

## Deployments of the Books demo

| Branch | Note | Vercel | Netlify | Cloudflare |
| --- | --- | --- | --- | --- |
| `main` | vibe port | https://svelte-books.vercel.app | https://svelte-books.netlify.app | https://svelte-books.to-email-max.workers.dev |
| `optimized` | cache + fonts | https://svelte-books-optimized.vercel.app | https://svelte-books-max-optimized.netlify.app | https://svelte-books-optimized.to-email-max.workers.dev |

## Benchmark, 2026-11-28

Tool: PageSpeed Insights v5 (Lighthouse lab run), mobile strategy. 3 measured runs per deployment, median reported; cold runs are left out of the median when a warm run exists. Each build's figure is the average of its hosts' medians (vercel, netlify, cloudflare). Pages measured: book list (/) and one book (/10145787). Times are lab values from one run on 2026-11-28. FCP is the Lighthouse estimate for simulated Slow 4G; Raw FCP, where shown, is the first paint in the real, unthrottled load that estimate is built from. Builds in the same FCP band (https://framework-compare.vercel.app/measured.md) are a tie, so read "fastest first" as band order.

| Page | Build | Branch | Hosts | Performance | FCP | Raw FCP | LCP | TBT | CLS |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| book list (/) | baseline | `main` | cloudflare, netlify, vercel | 85 | 1.52 s | 0.61 s | 4.26 s | 14 ms | 0.000 |
| book list (/) | optimized | `optimized` | cloudflare, netlify, vercel | 89 | 0.94 s | 1.26 s | 3.32 s | 4 ms | 0.000 |
| one book (/10145787) | baseline | `main` | cloudflare, netlify, vercel | 97 | 1.51 s | 0.61 s | 2.56 s | 20 ms | 0.000 |
| one book (/10145787) | optimized | `optimized` | cloudflare, netlify, vercel | 99 | 0.87 s | 0.68 s | 2.19 s | 7 ms | 0.000 |

Full run: https://framework-compare.vercel.app/benchmark.md

---

HTML version: https://framework-compare.vercel.app/frameworks/sveltekit · All pages: https://framework-compare.vercel.app/llms.txt · Data: https://framework-compare.vercel.app/api/index.json
