Local-first
Runs entirely in the browser through a Web Worker, so it keeps working offline after the first load.
Add run to a code fence and readers get a Run button with live console output. No server involved, and it keeps working offline.
A few variations of the same idea: run-only, editable, TypeScript, TypeScript combined with editing, and fetching data.
A plain run block. Readers can execute it, but not edit it.
console.log('hello from home');Add edit to the fence info string to let readers modify the code. Edits persist in localStorage, keyed to the block's source — if the author changes the example, the hash changes too and any stale edit is discarded automatically.
let total = 0;
for (let i = 1; i <= 5; i++) {
total += i;
}
console.log('total:', total);Use a ts fence for TypeScript. Types are stripped at runtime (not type-checked) before the code runs.
function add(a: number, b: number): number {
return a + b;
}
console.log('sum:', add(2, 3));ts and edit combine the same way — lazy type-stripping on run, lazy re-highlighting and persistence on edit.
interface Point {
x: number;
y: number;
}
function distance(p: Point): number {
return Math.sqrt(p.x * p.x + p.y * p.y);
}
console.log('distance:', distance({ x: 3, y: 4 }));Regular fetch() works inside the worker — this one hits a static JSON file served by this site. Relative paths don't resolve inside the worker's blob: URL, so build an absolute URL from self.origin first.
const res = await fetch(new URL('/example-data.json', self.origin));
const data = await res.json();
console.log(data);