In my last post on DEV I explained why I built Sitelo: most websites are documents, and documents shouldn't need a JavaScript application to reach the browser. That post was the argument. This one is the practice.
We'll build a small blog from an empty folder: a home page, post pages generated from JSON files, and a comments section that stays fresh on an otherwise static page. Along the way I'll point out what Sitelo is doing at each step, and what it deliberately doesn't do.
The whole framework fits in one sentence, and it's worth keeping in mind as we go:
Files are routes. Functions return HTML. Browser code is explicit.
Everything below is that sentence, applied.
Step 1: one page is one function
Start with an empty folder and install Sitelo. It needs Node 20.19+ or 22.12+, and Vite is bundled, so there's nothing else to install or configure.
npm init -y
npm pkg set type=module
npm install -D sitelo
Add two scripts to package.json:
"scripts": {
"dev": "sitelo",
"build": "sitelo build"
}
Now the first page. Any file in src/ ending in .ht.js is a page, and its default export returns HTML:
// src/index.ht.js
export default () => `
<html lang="en">
<head>
<title>My blog</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
`
Create a src/styles.css with a few rules, then run npm run build and you get:
dist/
index.html ← your HTML, with <!DOCTYPE html> added
styles.css ← bundled and minified, because the page linked it
404.html ← a default one, until you write src/404.ht.js
The function ran once, at build time, in Node. The browser gets the string it returned and nothing else: no runtime, no hydration, no bundle of page code. If you want JavaScript in the browser, you add a <script> tag, the same as you would in a hand-written HTML file.
Template literals aren't the only option. A page can also return JSX from a .ht.jsx or .ht.tsx file, which is rendered to a static string with react-dom/server. Or you can use my companion library javascript-to-html, where every element is a function. I'll stick with template literals here because they need no explanation.
Step 2: a layout is just another function
A blog needs the same <head> and header on every page. There's no layout system to learn for this, because a layout is a function that takes some HTML and wraps it:
// src/lib/layout.js
export const layout = ({ title, children }) => `
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${title} · My blog</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<header><a href="/">My blog</a> · <a href="/blog">Posts</a></header>
<main>${children}</main>
</body>
</html>
`
// src/index.ht.js
import { layout } from './lib/layout.js'
export default () => layout({
title: 'Home',
children: '<h1>Hello world</h1><p>Welcome to my blog.</p>',
})
layout.js doesn't end in .ht.js, so it isn't a page. It also never ends up in dist/. Sitelo only emits a JavaScript or TypeScript file when your HTML references it with a <script src>; a module you only import from page code stays on the build side. That rule matters more later, when the helpers you import hold API keys or database code. They can't leak into the browser by accident.
The same rule works in the other direction. Write <script type="module" src="/main.ts"></script> and Sitelo bundles src/main.ts with esbuild, emits main.js, and rewrites the tag to match. Browser code exists only where you asked for it.
Step 3: posts from JSON files
Now for the posts. I'll keep them in the repo as JSON, one file per post, outside src/ because they're content rather than code:
// data/posts/hello-world.json
{
"title": "Hello, world",
"date": "2026-10-01",
"body": "<p>My first post.</p>"
}
The post page lives at src/blog/[slug].ht.js. The square brackets make it a dynamic route, and it exports two more functions next to the page itself:
generateStaticParams() lists the pages to build, one per post.
data() loads what one page needs. Whatever it returns arrives in the page function as data.
// src/blog/[slug].ht.js
import { readJsonCollection } from 'sitelo/data'
import { layout } from '../lib/layout.js'
const posts = () => readJsonCollection('data/posts', { sort: '-date' })
export async function generateStaticParams() {
return (await posts()).map((post) => ({ slug: post.slug }))
}
export async function data({ params }) {
return (await posts()).find((post) => post.slug === params.slug)
}
export default ({ data: post }) => layout({
title: post.title,
children: `
<article>
<h1>${post.title}</h1>
<time datetime="${post.date}">${post.date}</time>
${post.body}
</article>
`,
})
readJsonCollection reads every .json file in the folder and takes each slug from its file name. It parses each file once per build, however many pages ask for it, and two posts with the same slug fail the build instead of one silently overwriting the other.
The index page is the same idea without the brackets:
// src/blog/index.ht.js
import { readJsonCollection } from 'sitelo/data'
import { layout } from '../lib/layout.js'
export const data = () => readJsonCollection('data/posts', { sort: '-date' })
export default ({ data: posts }) => layout({
title: 'Posts',
children: `
<h1>Posts</h1>
<ul>
${posts.map((post) => `<li><a href="/blog/${post.slug}">${post.title}</a></li>`).join('')}
</ul>
`,
})
A build now writes dist/blog/index.html and one dist/blog/<slug>/index.html per post. In the dev server (npm run dev) pages render on request through Vite, so editing a JSON file reloads the browser, and an error points at the exact line of your page in the terminal.
If your posts live in a CMS instead, data() can fetch them. Sitelo exports fetchWithCache, a drop-in for fetch that caches responses during the build. A 500-page site then doesn't make 500 identical requests to your API.
Comments are the classic reason static blogs reach for a client-side widget or give up and go server-rendered. Sitelo's answer is a server island: the page stays static, and one marked region is rendered on the server when someone views it.
An island is a module in src/islands/ whose default export returns HTML. Islands are fragments rather than pages, so the file is plain .js, not .ht.js:
// src/islands/comments.js
import { getComments } from '../lib/comments.js'
const escape = (s) => String(s).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`)
export default async function comments({ props }) {
const list = await getComments(props.postId)
if (!list.length) return '<p>No comments yet.</p>'
return `<ul>${list.map((c) => `<li><b>${escape(c.author)}</b> ${escape(c.text)}</li>`).join('')}</ul>`
}
getComments is whatever your comment store is: a database query, a call to a hosted service. Comments are user input, hence the escape.
Place the island in the post page with island(). The third argument is the fallback HTML that ships in the static build, and when: 'visible' waits until the reader scrolls near the comments before making the request:
// src/blog/[slug].ht.js (the page function)
import { island } from 'sitelo/islands'
export default ({ params, data: post }) => layout({
title: post.title,
children: `
<article>…</article>
${island('comments', { postId: params.slug }, '<p>Loading comments…</p>', { when: 'visible' })}
<script type="module" src="/islands.js"></script>
`,
})
The script tag loads a two-line client that finds the placeholders and fetches them:
// src/islands.js
import { mountIslands } from 'sitelo/islands/client'
mountIslands()
In npm run dev and sitelo preview this already works: Sitelo serves islands at /_sitelo/islands/<name>. In production your static host serves the pages, and you mount a small handler wherever you can run server code. createIslandsHandler from sitelo/islands/server takes a Web Request and returns a Response, so it fits a serverless or edge function. The repo has Netlify and Vercel versions.
A few details I cared about getting right:
- Props are untrusted. They're embedded in the page and sent back on the request, so anyone can edit them. Set
SITELO_ISLANDS_SECRET and the build signs every placeholder with HMAC-SHA256, and the handler rejects edited props with a 403.
- Islands are server-only. The rule from Step 2 applies: nothing references
comments.js from HTML, so it never reaches dist/, and neither does your database code.
- Failure is graceful. If the island endpoint is down or slow (10 seconds by default), the fallback HTML stays where it was. The page still works.
Step 5: let the build check your work
The blog works. The last step is a config file, and it's where Sitelo earns its keep on a real site:
// sitelo.config.js
export default {
site: 'https://myblog.example',
rss: {
site: 'https://myblog.example',
title: 'My blog',
description: 'Latest posts',
routePrefix: '/blog',
},
images: true,
linkCheck: 'error',
lighthouse: {
thresholds: { accessibility: 100, 'best-practices': 95, seo: 100 },
},
}
Here's what each line buys you:
site generates dist/sitemap.xml from every route, including the ones generateStaticParams produced.
rss writes dist/rss.xml with an item for every page under /blog.
images turns each <img> into a resized, WebP srcset with width and height set, so a 3000px hero photo no longer ships to phones. It needs sharp installed, and it works in the dev server too, so what you see is what you ship.
linkCheck: 'error' resolves every internal <a href> against the files the build actually wrote, the way a static host would. A typo like /blgo fails the build with the page it's on.
lighthouse gives sitelo lighthouse thresholds to enforce. Any score under its threshold exits non-zero, so it can gate CI. Like sharp, Lighthouse is an optional install.
I left performance out of the thresholds on purpose. It depends on the machine running the audit, and a page that scores 100 on a laptop can score around 60 on a shared CI runner. Accessibility, best practices and SEO are properties of the HTML itself, so they score the same anywhere.
One check needs no config. If a page links a script or stylesheet that doesn't exist in src/ or public/, the build fails and lists the paths it tried. That's why Step 1 asked you to create styles.css first.
Every build ends with a report of what you're shipping: file counts and sizes per type, the largest files, and how long each phase took. On a static site, "how much JavaScript am I sending?" should be a number you see every time, not something you go looking for.
Building it with a coding agent
I designed Sitelo with coding agents in mind, and the small surface area matters even more for them than for people. Ask an agent to add a page to an unfamiliar framework and it reaches for whatever it has seen most: React components, Next.js conventions, Astro frontmatter. With Sitelo there's less to get wrong, because there's less of everything. A page is a function, a route is a file, and browser code is a <script> tag.
To close the remaining gap, Sitelo ships two Agent Skills: one for the framework (pages, routing, data, islands, deployment) and one for its component library. Install them into your project and Claude Code, Cursor, Codex and other agents load them when a task needs them:
npx skills add Paul-Browne/sitelo
The skills also ship inside the npm package, matching the version you installed. Sitelo's test suite checks every API the skills mention against the package's real exports, so a renamed or removed API fails the tests before it reaches a release. For agents that prefer to read a URL, the docs publish sitelo.dev/llms.txt, plus a single-file llms-full.txt with every guide in Markdown.
The build checks from Step 5 help here too. An agent that invents a stylesheet path or links to a page that doesn't exist gets a failed build naming the problem, not a site that quietly ships broken.
What we built, and when not to use it
In five steps we went from an empty folder to a blog with:
- a home page, a post index and one page per JSON file
- comments rendered on the server at view time, on otherwise static pages
- a sitemap, an RSS feed and responsive images
- a build that fails on broken links and missing assets, plus a Lighthouse gate for accessibility and SEO
The browser receives HTML, one stylesheet and a 1.7 kB island loader. That's all, because those are the only things we asked for.
Sitelo isn't the right tool for everything. JSX pages render to static HTML only, so onClick handlers and hooks do nothing in the browser. If you're building an application, with client-side state and routing, use an application framework. Astro, Next.js and Eleventy are all excellent at what they do. Sitelo is for docs, blogs, marketing sites and content sites, where "view source" should show what you wrote.
If that sounds like your next project:
The repo includes a complete blog example that goes further than this post, with Markdown posts. And if you find something that makes Sitelo more complicated than it needs to be, please open an issue. Keeping it boring is the whole point.