A zero-JavaScript personal site with Astro 7

How this site ships static HTML by default, where the few kilobytes of JavaScript go, and how build-time rendering replaces client-side work.

4 min read updated

Abstract dark cover with a fine dotted grid and a single cyan accent line

A personal site has an unusual brief. It has a handful of pages, one author, and readers who mostly want to read. That is the best case for shipping almost no JavaScript, and Astro makes the default the right one.

This post walks through the setup behind this site: what renders at build time, what little runs in the browser, and the habits that keep it that way.

The architecture in one picture

Content lives as Markdown and MDX files next to their images. Astro validates them against schemas, renders them to static HTML, and writes plain files to disk. A web server only has to hand them out.

Markdown and MDX

Content schemas

Astro build

Images

Static HTML and CSS

nginx

Reader

Every arrow on the left of the server happens once, at build time. The reader’s browser never repeats that work.

Typed content, checked at build

The content layer is the part I would copy first. Each collection declares a schema, so a typo in a date or a missing description fails the build instead of shipping.

src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '*/index.{md,mdx}', base: './src/content/blog' }),
schema: z.object({
title: z.string().max(80),
description: z.string().min(50).max(160),
pubDate: z.coerce.date(),
tags: z.array(z.string()).default([]),
}),
});
export const collections = { blog };

Length limits on titles and descriptions look fussy, but they catch search snippets that would be truncated, before a reader sees them.

Co-located assets

Each post is a folder. The cover image sits beside index.md, and the schema’s image() helper checks that the file exists. Rename the folder and the references move with it.

Drafts

A draft flag hides unfinished work in production and shows it in development. One boolean, no separate branch to maintain.

The JavaScript budget

I give the site a budget and write it down, so exceptions are visible. There are three.

  1. A tiny inline script that applies the saved theme before first paint, to avoid a flash.
  2. The copy button on code blocks, about 1 kB.
  3. Opt-in islands for genuinely interactive widgets, hydrated only when scrolled into view.

Everything else is HTML and CSS. Diagrams like the one above are rendered to inline SVG during the build, so no charting library reaches the browser.

Hydrating only when needed

When a component does need behaviour, an island directive keeps the cost local:

---
import Counter from '../components/Counter.astro';
---
<Counter client:visible />

The directive means the script is fetched only when the element enters the viewport. A reader who never scrolls that far never pays for it.

Keeping it honest

The budget only works if it is checked. I look at the built output for <script> tags after every significant change, and a CI job fails if the network panel shows unexpected requests. A rule you do not measure is a wish.

What this buys

Static output has second-order benefits that are easy to underrate.

  • Speed. There is nothing to hydrate, so the main thread stays free.
  • Resilience. The site works with scripts blocked, on slow networks, and in reader modes.
  • Simple hosting. A small container serving files has few moving parts to patch.
  • Longevity. HTML from today will render in ten years. A framework runtime might not.

Trade-offs

This is not free. Anything dynamic, like search or comments, needs either a build-time approach or a deliberate island. I chose to skip comments entirely. Search can be generated as a static index when the post count justifies it, and not before.

Build times also grow with content, since every page is rendered ahead of time. At a few hundred pages that stays comfortable. At tens of thousands it is a different conversation.

Takeaways

Start from zero JavaScript and add it on purpose. Validate content with schemas so mistakes fail loudly. Render diagrams and highlighting at build time. Write the budget down, and measure it.

The source for this site is public, so you can read exactly how each piece is wired.