Why I Build My Frontends in Svelte
I build my frontends in Svelte, which is a less common choice than React. Three of my projects use it. All three started on Svelte 5 with runes, so none has needed a migration from the older syntax.
Svelte gave me less boilerplate and small static builds. It costs a smaller ecosystem and a smaller pool of people who already know it. In the 2025 Stack Overflow survey, 44.7% of respondents had done extensive work in React in the past year, and 7.2% in Svelte.
In short
- Svelte is a compiler. In the lab, a small counter compiles to 537 bytes of direct DOM updates.
- Built with the same bundler, the same counter is 19,232 B gzip in Svelte 5.56.10 and 69,187 B in React 19.3.1. In Lighthouse both score 100, and the Svelte page's largest paint comes 0.3 s sooner on simulated mobile. A counter is a tiny app.
- Svelte 5 runes ($state, $derived, $effect, $props) replace
let,$:andexport let. Svelte 4 code still compiles by default. - In my three frontends, $derived appears between about 4.6 and 30 times as often as $effect.
- The costs: a smaller ecosystem and hiring pool, fewer ready-made component libraries, a syntax change between versions 4 and 5, and SvelteKit settings that must match the hosting.
What Svelte is
The Svelte docs call it "a framework for building user interfaces on the web" that "uses a compiler to turn declarative components written in HTML, CSS and JavaScript" into "lean, tightly optimized JavaScript". The markup becomes a template that is cloned once. Each reactive value gets code that writes to the one text node or attribute it feeds. In the lab, the compiled counter contains no virtual DOM tree.
React works another way. Rendering is "React calling your components", and the commit step "will apply the minimal necessary operations" to make the DOM match. That is a runtime model, and it is not a flaw. React also moves work to the build: React Compiler applies "the equivalent of manual memoization" automatically. Without it, a state change re-renders the component and all its children unless you memoise.
Svelte 5 and runes
Svelte 5 became stable on 22 October 2024 and is "almost completely backwards-compatible with Svelte 4". Runes were introduced in a post of 20 September 2023. It lists the problems they fix. Svelte 4 reactivity worked only for top-level let declarations. Code behaved one way in .svelte files and another in .js. A $: statement could only "see" the variables named in it. The store API "can get rather unwieldy when you start doing more complex things".
The migration guide maps old forms to new ones, shown below. Old and new components can be mixed. The migration script (npx sv migrate svelte-5) does not convert createEventDispatcher or beforeUpdate and afterUpdate.
| Svelte 4 | Svelte 5 | Note from the migration guide |
|---|---|---|
let count = 0 | let count = $state(0) | A variable is reactive when created with $state. |
$: double = count * 2 | const double = $derived(count * 2) | $derived replaces derivations. |
$: { sideEffect(count) } | $effect(() => sideEffect(count)) | $effect replaces side effects. |
export let name | let { name } = $props() | All properties come through $props, by destructuring. |
on:click={fn} | onclick={fn} | Handlers are properties like any other. |
createEventDispatcher | callback props | Deprecated; the migration script does not convert it. |
<slot /> | {@render children()} | Snippets replace slots. |
| stores | a class or object with $state in a .svelte.js file | The guide page does not cover stores. The runes post calls the store API “unwieldy” for complex cases. |
For deep state, the $state page says an array or simple object becomes "a deeply reactive state proxy". "Class instances are not proxied", but a class can use $state in its fields. Runes are compiler syntax, so they work only in .svelte, .svelte.js and .svelte.ts files. In the lab, the same text run as plain JavaScript fails with "$state is not defined".
The same component in Svelte and React
Here is one small component in each: a counter with a derived value, an effect that sets the page title, and a list you can add to. I wrote both for this post. As written, the Svelte file is 17 lines and the React file is 23.
<script>
let count = $state(0);
let items = $state(['a', 'b']);
const double = $derived(count * 2);
$effect(() => {
document.title = `count ${count}`;
});
</script>
<button onclick={() => count++}>{count} doubled is {double}</button>
<button onclick={() => items.push('x' + items.length)}>add</button>
<ul>
{#each items as item}
<li>{item}</li>
{/each}
</ul>
import { useState, useMemo, useEffect } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
const [items, setItems] = useState(['a', 'b']);
const double = useMemo(() => count * 2, [count]);
useEffect(() => {
document.title = `count ${count}`;
}, [count]);
return (
<>
<button onClick={() => setCount(count + 1)}>{count} doubled is {double}</button>
<button onClick={() => setItems([...items, 'x' + items.length])}>add</button>
<ul>
{items.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
</>
);
}
The difference is mostly in the list and the derived value. Svelte mutates the array and tracks the change. React needs a new array and a dependency list for useMemo and useEffect.
I also built both with the same bundler and settings: esbuild, minified, production mode, ES module output. The table gives the result.
| Same counter, esbuild, minified | Svelte 5.56.10 | React 19.3.1 + react-dom 19.3.1 |
|---|---|---|
| Source lines as written | 17 | 23 |
| Bundle, raw | 51,688 B | 223,893 B |
| Bundle, gzip level 9 | 19,232 B | 69,187 B |
A counter is a tiny app. The React figure is mostly the library, and the Svelte figure is mostly its runtime, so both are fixed costs that matter less as an app grows. For scale, the genealogy site's whole client is about 104 kB gzip (see the build table below), and that is a different build tool.
I also ran Lighthouse 12.8.2 on both builds, five times each, with its default mobile settings: a simulated slow 4G network and a CPU four times slower. A local server sent both pages gzipped. The table gives the medians, and the five runs of each page were within 4 ms of each other.
| Lighthouse, mobile | Svelte 5.56.10 | React 19.3.1 |
|---|---|---|
| Performance score | 100 | 100 |
| First contentful paint | 0.90 s | 1.05 s |
| Largest contentful paint | 0.90 s | 1.20 s |
| Total blocking time | 0 ms | 0 ms |
| Transferred, gzip | 20,025 B | 70,170 B |
Both pages score 100, and neither blocks the main thread. The Svelte page shows its content 0.15 s sooner at first paint and 0.30 s sooner at largest paint, which follows the extra 50 kB the React page sends over the simulated network. These are simulated timings for a counter, not a measure of either framework in a real app.
A worked trace
The lab's Series class has three $state fields and three $derived values. Each derived value counts how often it runs. After one write to title, one derived value runs again. A model that re-runs everything would run three.
const s = new Series(); // values, unit, title: $state; total, mean, label: $derived
s.title = 'level'; // 1 write
// total: depends on values only -> not marked, not run
// mean: depends on total and values -> not marked, not run
// label: depends on title and unit -> marked dirty, runs on next read
| Step | What happens | Runs again? |
|---|---|---|
| Start | values, unit, title are $state; total, mean, label are $derived | none yet: derived values are lazy |
| First read of all three | each derived value is computed once | total 1, mean 1, label 1 |
title = 'level' | only label reads title, so only it is marked stale | label on its next read |
| Second read of all three | total and mean return their stored values | label 2, total 1, mean 1 |
Series class. Only the boxes downstream of the written node run again.Two more lab results. A value read twice is computed once. An effect that reads two fields runs once after two writes.
SvelteKit, plain Vite and adapter-static
Svelte renders components. SvelteKit adds "a router that updates your UI when a link is clicked", server-side rendering and "build optimizations to load only the minimal required code". A plain Vite project with the Svelte plugin gives you components and a bundler, and you add routing yourself.
adapter-static "will prerender your entire site as a collection of static files", which any file host can serve. The root layout must set prerender. Keep ssr on when pages should carry their content: with ssr false, prerendering "saves an empty shell page". A dashboard rendered in the browser wants exactly that (pattern 5 below); a content site does not. The fallback option makes a single-page app, but it "has large negative performance and SEO impacts". By default the adapter checks that every page is prerendered or a fallback is set.
import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({ pages: 'build', assets: 'build', fallback: '404.html', strict: true }),
prerender: { entries: ['*', '/sitemap.xml'], handleHttpError: 'fail' }
}
};
Three frontends, measured
The three projects are a genealogy project's website, a Y-DNA tree viewer whose code is closed, and a private research cockpit. The first uses SvelteKit with adapter-static. The second uses Vite with the Svelte plugin and no SvelteKit. The third is SvelteKit built as a static shell that renders in the browser. Counts are lines of the tracked .svelte files. Sizes come from production builds already on disk. Gzip sizes are approximate: I concatenated each build's JavaScript and compressed it at the default level.
| Genealogy site | Tree viewer | Research cockpit | |
|---|---|---|---|
| Tooling | SvelteKit, adapter-static | Vite + Svelte plugin | SvelteKit, adapter-static, browser-rendered |
| Svelte | 5.56.10 | 5.56.8 | 5.57.3 |
| SvelteKit / Vite | 2.70.3 / 8.2.2 | none / 8.1.5 | 3.1.1 / 8.3.6 |
| TypeScript | 6.0.3 | 6.0.3 | 6.0.3 |
| Svelte adopted | 2026 (November) | 2026 (July) | 2026 (November) |
| Runes from first commit | yes | yes | yes |
| Components (.svelte files) | 58 | 68 | 39 |
| Lines in those files | 5,076 | 25,632 | 5,095 |
| Lines of TypeScript (tests included) | 1,624 | 39,464 | 8,518 |
| Svelte 4 store API | not used | not used | not used |
| Shared state | components, two module objects | rune modules | class passed by context |
| Backend | static JSON at build time | fetch, same origin | typed fetch, event stream |
I searched each history for export let and found nothing. $state appears in each project's first Svelte commit. So there is no runes migration in any of them, and I cannot report its cost. All three are from 2026, so they say little about how Svelte ages.
| Production build on disk | Script files | JavaScript | JavaScript, gzip | CSS |
|---|---|---|---|---|
| Genealogy site (39 pages) | 55 | 255,462 B | 103,760 B | 79,162 B |
| Tree viewer | 36 | 1,037,931 B | 363,452 B | not measured |
| Research cockpit | 12 | 280,305 B | 92,592 B | 55,256 B |
The tree viewer is the largest application, and its views load on demand. The table gives its total over 36 chunks, not what one page loads. The genealogy site's 39 HTML files share its 55 script files. The cockpit's client is 12 script files. I did not build React versions of these projects, so none of this compares the two.
Patterns from the code
Five patterns recur. The snippets are new, written to show the idea.
1. Shared state as a module. One $state object in a .svelte.ts file, with small functions that write to it. The tree viewer has eight such modules and no stores. The genealogy site has two.
// highlight.svelte.ts: shared state as one $state object plus small functions that write to it.
export const highlight = $state({ ids: new Set<string>(), label: null as string | null, epoch: 0 });
export function setHighlight(ids: string[], label: string): void {
highlight.ids = new Set(ids);
highlight.label = label;
highlight.epoch += 1; // views react to a new request, not only a changed set
}
2. A class with runes in its fields. The cockpit wraps each remote value in a class that holds data, error and loading. It drops answers from older requests and keeps old data when a refresh fails. The lab tests it without a browser.
// One remote value: loading until the first answer, then the data or an error message.
// The newest request wins, an older answer that arrives late is dropped, and old data
// stays on screen if a refresh fails.
export class Resource {
data = $state(null);
error = $state(null);
loading = $state(true);
#latest = 0;
#load;
constructor(load) {
this.#load = load;
}
async refresh() {
const mine = ++this.#latest;
try {
const data = await this.#load();
if (mine !== this.#latest) return;
this.data = data;
this.error = null;
} catch (e) {
if (mine !== this.#latest) return;
this.error = e instanceof Error ? e.message : String(e);
} finally {
if (mine === this.#latest) this.loading = false;
}
}
}
3. Context for the store. The cockpit creates one such object in the layout and passes it down with Svelte's context API. The getter fails loudly if the layout is missing.
import { getContext, setContext } from 'svelte';
import type { Cockpit } from './cockpit.svelte';
const KEY = Symbol('cockpit');
export const setCockpit = (c: Cockpit): Cockpit => setContext(KEY, c);
export function getCockpit(): Cockpit {
const c = getContext<Cockpit | undefined>(KEY);
if (!c) throw new Error('Cockpit context missing: wrap the page in +layout.svelte');
return c;
}
4. A derived layout for an SVG chart. Geometry lives in a plain TypeScript function. The component derives its points from the data and its measured width. At least two of the three projects draw charts by hand, in SVG or on a canvas.
<script lang="ts">
import { layout, W, H, type Series } from '$lib/chart';
let { series }: { series: Series[] } = $props();
let box = $state(0); // rendered width, bound below
// Recomputed only when `series` or `box` change.
const geo = $derived(layout(series, box > 0 ? Math.max(300, Math.round(box)) : W));
</script>
<figure bind:clientWidth={box}>
<svg viewBox="0 0 {geo.width} {H}" role="img" aria-label="Line chart">
{#each geo.series as s}
<polyline points={s.points} fill="none" stroke="currentColor" />
{/each}
</svg>
</figure>
5. A browser-rendered shell. For a dashboard whose data exists only at run time, two lines in the layout give a static shell: prerender the page, and do not render it on the server.
// +layout.ts of a browser-rendered dashboard: one prerendered shell, data fetched at run time.
export const prerender = true;
export const ssr = false;
None of the three uses the Svelte 4 store API. The genealogy site keeps runes in components plus two module objects. The tree viewer uses component runes and rune modules. The cockpit passes a class-based store by context.
For backends, the genealogy site reads static JSON at build time and fetches only a search index at run time. The tree viewer calls its API with fetch from the same origin. The cockpit uses a typed fetch client generated from the API's schema, a server-sent event stream and periodic refreshes. All three test with Vitest. The genealogy site adds build-level checks. The tree viewer uses happy-dom. The cockpit uses jsdom and Testing Library, with tests beside the components.
Pros and cons
Sources are in parentheses.
| Pros (with source) | Cons (with source) |
|---|---|
| Components compile to “lean, tightly optimized JavaScript” (Svelte docs, overview). | Smaller user base: React 44.7% and Svelte 7.2% of all respondents with extensive work in the past year; among professional developers 46.9% and 6.9% (Stack Overflow Developer Survey 2025). |
| With runes “you can write less code” (Svelte blog, “Introducing runes”, 20 September 2023). | Fewer people use it at work: 8,548 respondents used React and 1,409 used Svelte (State of JavaScript 2024). That points to a smaller hiring pool and fewer libraries. |
| Fine-grained updates: “changes to a value inside a large list needn't invalidate all the other members” (same blog post). | Syntax change: slots, events and export let have new forms in Svelte 5, and the migration script does not convert createEventDispatcher, beforeUpdate or afterUpdate (Svelte 5 migration guide). |
| adapter-static “will prerender your entire site as a collection of static files” (SvelteKit docs). | Settings must match hosting: with ssr off, prerendering “saves an empty shell page”, and the fallback option “has large negative performance and SEO impacts” (SvelteKit docs, adapter-static). |
| Svelte 5 is “almost completely backwards-compatible with Svelte 4” (Svelte blog, 22 October 2024). | Compiler-only syntax: runes work in .svelte and .svelte.js files, not plain modules (lab test; $state is not defined). |
Why I chose it
I tried React before and disliked it. For what I build it felt heavier than the work needed. Three reasons sit behind that, and they are the pros that mattered to me.
Less code and a plain feel. I wanted less code and something close to plain HTML, CSS and JavaScript: no JSX, no rules of hooks, less boilerplate. This matches the documented pro that runes mean you "can write less code". The evidence supports it only partly. A component is one file with script, markup and style, and the counter above is 17 lines against 23. But I did not rewrite any project in React, so I cannot put a figure on the saving, and the tree viewer's components are long: its tracked .svelte files have a median of 305 lines, including their styles.
Small, fast static builds. I like that the framework compiles away and that the sites host anywhere through adapter-static. That is the compiler pro and the static-files pro from the table. The evidence: the counter bundles to 19.2 kB gzip in Svelte against 69.2 kB in React, and the genealogy site serves 39 prerendered pages from 55 script files. The tree viewer is the counter-example: about 1,038 kB of JavaScript across 36 chunks, which is the size of its features, not of its framework.
Easy for a backend and ML engineer, and productive alone. Svelte lets me be productive by myself on side projects. Two of the three projects hold more TypeScript than Svelte markup (the tree viewer and the cockpit), and the cockpit's store is an ordinary class. That is consistent with state and logic living in plain code, though it does not prove ease of learning.
The cost side. The repositories show one cost: the genealogy site's history has a commit that fixes pages failing to hydrate by using one Svelte version. That is a dependency problem, not a language one. They show no runes migration, because none of the three needed one. The smaller ecosystem and hiring pool are general trade-offs that follow from the survey figures above. The tree viewer uses a mapping library and a flags package that do not depend on a framework, and at least two projects draw their charts by hand. My records do not say whether that was a choice or a lack of options.
When I would not pick Svelte
- When the team or the people I hand it to know React. The hiring pool is smaller (Stack Overflow 2025, State of JavaScript 2024).
- When the project needs many ready-made component libraries. Fewer users point to fewer of them.
- When I have a large Svelte 4 codebase built on slots and event dispatchers and no time to port it. The migration script does not do all of it.
- When I cannot prerender the pages. adapter-static needs prerendered pages or a fallback, and the fallback has large negative performance and SEO impacts.
A small lab you can run
The lab is a folder with Svelte 5 and a few files, and no bundler. A script compiles the sources with Svelte's own compiler, and the tests check each claim above against the alternative it rejects.
store.svelte.js: theSeriesclass. Tests cover lazy evaluation, one recomputation against three, deep reactivity onpushand one effect run after two writes.resource.svelte.js: the pattern-2 class. A late answer to an older request is dropped, and a failed refresh keeps the old data.Counter.svelte, compiled for the client: the output is a cloned template and a text write, with no virtual nodes.Chart.svelte, compiled for the server: it renders to a string with the right point count andpointsattribute.Legacy.sveltein the Svelte 4 style: it compiles by default and is refused withrunes: true.- The counter built with Svelte 5 and with React 19 by esbuild: sizes are identical on two builds, and the React bundle is larger. An optional script runs Lighthouse on both.
Run npm install and npm test, or python -m pytest -q. It passes 15 tests. node --conditions browser demo.js prints the compiled counter and the chart string. node --conditions browser bundle.js prints the bundle sizes, and node lighthouse.js repeats the Lighthouse runs if Chrome is installed.
Limits of this post
- The three projects are small to medium and from 2026. They show how I use Svelte, not how it behaves in a large team or over years.
- Apart from the counter's bundle size and its simulated Lighthouse timings, there is no React comparison, so nothing here says Svelte is faster or smaller than React for a real application.
- Gzip figures are approximate, and I did not measure what a single page downloads.
- Rune counts are text matches, comments included.
- The Stack Overflow figure measures extensive work in the past year, not hiring supply.
Sources
- Svelte documentation, overview: svelte.dev/docs/svelte/overview
- Svelte documentation, $state: svelte.dev/docs/svelte/$state
- Svelte 5 migration guide: svelte.dev/docs/svelte/v5-migration-guide
- SvelteKit introduction: svelte.dev/docs/kit/introduction
- SvelteKit page options: svelte.dev/docs/kit/page-options
- SvelteKit adapter-static: svelte.dev/docs/kit/adapter-static
- Svelte blog, Svelte 3 release post, 22 April 2019: svelte.dev/blog/svelte-3-rethinking-reactivity
- Svelte blog, Svelte 4 release post, 22 June 2023: svelte.dev/blog/svelte-4
- Svelte blog, "Introducing runes", 20 September 2023: svelte.dev/blog/runes
- Svelte blog, "Svelte 5 is alive", 22 October 2024: svelte.dev/blog/svelte-5-is-alive
- React documentation, "Render and Commit": react.dev/learn/render-and-commit
- React documentation, React Compiler introduction: react.dev/learn/react-compiler/introduction
- Stack Overflow Developer Survey 2025, technology: survey.stackoverflow.co/2025/technology
- State of JavaScript 2024, front-end frameworks: 2024.stateofjs.com/en-US/libraries/front-end-frameworks