Building This Site With SvelteKit

This site is small. A handful of pages, a few write-ups, no backend. That made it a good place to be strict about the boring parts: what ships to the browser, what happens before JavaScript runs, and what a visitor sees on a slow phone.

The stack

It’s SvelteKit with adapter-static, so every page is prerendered to plain HTML at build time and served from GitHub Pages. Posts and project write-ups are Markdown, compiled by mdsvex into Svelte components. Svelte 5 runes mode is forced for the whole project, so there’s one way to write state and props instead of two.

A few rules keep it honest:

  • Every internal link ends in a slash. trailingSlash = 'always' plus resolve() for every link, so a typo fails the type check instead of becoming a redirect. I wrote about why the slash matters in another post.
  • Motion is CSS only. No animation library. The one piece of JavaScript involved in animation, a scroll reveal, only toggles a class. CSS does the rest, and one prefers-reduced-motion block turns all of it off.
  • Nothing is hand-maintained twice. The sitemap, llms.txt and the “what’s new” feed are all generated from the same data the pages use.

Pixel art without a canvas

The logo and the intro are drawn from a tiny 5×7 bitmap font that lives in a TypeScript file. The first version painted each letter into a <canvas> after the page loaded. It looked fine on a fast laptop.

Measuring it changed that. A canvas has no content until JavaScript draws it, and it starts at a default size of 300×150 pixels. So on a slow connection the intro was a blank screen, and on every load the canvases jumped to their real size once the script ran. Lighthouse reported that as a layout shift of about 0.17 on every desktop page.

Now the same bitmap becomes an SVG path at build time, one small square per lit pixel. It’s in the HTML from the first byte, it’s sized by CSS, and it never moves. Layout shift went to zero.

An intro that knows when to stay out of the way

The intro spells out “Welcome to the portfolio of…” before the homepage appears. I like it, so it stays, but it used to play on every full page load, including someone opening a blog post from a shared link.

It now plays once per browser tab, and only on the homepage. A small inline script in app.html makes that decision before the first paint, so when the intro isn’t going to play, it never flashes. Any click or key ends it early, and with reduced motion turned on the line appears whole instead of typing out.

Fonts were the slowest thing on the page

The fonts came from a Google Fonts @import at the top of the stylesheet. That’s three requests in a row before any text can render: the page, then the stylesheet, then Google’s stylesheet, then the font files. It also sent every visitor’s IP address to Google.

They’re self-hosted now: two families, Latin subsets only, about 52 KB together, with the main one preloaded. Together with the other fixes, first paint on a throttled phone in Lighthouse went from about 3.8 seconds to 2.6.

A setting I changed and put back

SvelteKit can ship the whole site as one JavaScript bundle (bundleStrategy: 'single') or split it per page. Lighthouse flags the single bundle as unused JavaScript, so I tried splitting it.

The build looked fine. Every page was broken. Combined with paths.relative: false, which the 404 page needs, the split build wrote chunk URLs with /_app/immutable/ in them twice, so nothing hydrated and every page fell through to “Page not found”. The end-to-end tests caught it straight away.

I went back to one bundle. It also turns out to be a feature: once the first page loads, moving between pages takes about 50 milliseconds and keeps working offline. There’s now a comment in the config saying so, so I don’t try it again blind.

What I’d tell someone building their own

Measure in a real browser, at real sizes, with the settings people actually use. Most of what was wrong here wasn’t visible on a fast laptop with animations on, and none of it was hard to fix once a number pointed at it.