No dependencies. No build step. Just HTML, CSS and JavaScript.
Mastro is a server framework and static site generator for people who care about their users and web standards. Build fast server-rendered websites, ship JavaScript for islands only.
Implemented in just ~900 lines of TypeScript, Mastro is a vanishingly thin layer: your server code runs directly on Node.js, your unobfuscated client code directly on the high-performance rendering engine that is a modern browser.
As seen on the Internet!
Mastro's source code is extremely readable.
– Erik Onarheim
A library worth checking out!
– Jared White
Simple to start, powerful when you need it
- No bloat: implemented in just ~900 lines of TypeScript, Mastro is fast.
- No build step (until you add one): your code ships exactly how you wrote it.
- No JavaScript (until you ship some): create fast content-driven MPA websites.
- No dependencies: use web standards instead of keeping up with the frontend treadmill.
- No VC-money: no eventual enshittification – selling is none of our business.
- No lock-in: swap out Mastro or fork it – it’s open source and only ~900 lines.
Fast server-rendered HTML
Whether you do static site generation or use Mastro as a full-stack framework, your route handlers are always plain functions returning a web standard Response. You can compose the built-in HTML helpers, or use a different templating language.
You control precisely what code stays on the server, and what gets shipped to the browser. To keep your website fast, the default is the server.
import { readMarkdownFiles } from "@mastrojs/markdown";
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";
export const GET = async () => {
const posts = await readMarkdownFiles("posts/*.md");
return htmlToResponse(
Layout({
title: "My blog",
children: posts.map((post) => html`
<p>${post.meta.title}</p>
`)
})
);
};
import { html, type Html } from "@mastrojs/mastro";
interface Props {
title: string;
children: Html;
}
export const Layout = (props: Props) =>
html`
<!DOCTYPE html>
<html lang="en">
<head>
<title>${props.title}</title>
</head>
<body>
<h1>${props.title}</h1>
${props.children}
</body>
</html>
`;
Interactive user interfaces
To add client-side interactivity, either use plain JavaScript, or add a library. Popular examples include HTMX, Alpine, Datastar, Unpoly, ArrowJS, or Reactive Mastro. Even Preact and Vue.js work without a complex build tool like Vite.
Reactive Mastro lets you share templates and logic between the server and client islands. It also allows you to initialize state directly from your server-generated HTML – without duplicating the data as JSON.
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";
export const GET = () =>
htmlToResponse(
Layout(html`
<script type="module" src="/my-counter.client.js"></script>
<my-counter>
Count is <span data-bind="count">0</span>
<button data-onclick="inc">Click me</button>
</my-counter>
`)
);
import { ReactiveElement, signal } from "@mastrojs/reactive";
customElements.define("my-counter", class extends ReactiveElement {
count = signal(parseInt(this.querySelector("span").textContent));
inc () {
this.count.set(c => c + 1);
}
});
Everything is a route
In Unix, everything is a file. In Mastro, everything is a route. Using web standard Request/Response handlers is such a great interface that Mastro decided to go all-in on it. Write a simple function to:
- return HTML or component-scoped CSS
- process an HTML form
- do a redirect
- build a JSON REST API (optionally with tRPC-like type-safety)
- transform images
- etc.
Even Mastro’s middleware is using the same fetch handler API.
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";
export const GET = () =>
htmlToResponse(
Layout(html`
<form action="." method="POST">
<label>
E-Mail
<input type="email" name="email">
</label>
<button>Subscribe</button>
</form>
`)
);
export const POST = async (req: Request) => {
const data = await req.formData();
await db.subscriptions.insert({ email: data.get("email") });
return Response.redirect(new URL("/thanks", req.url), 303);
};
import { jsonResponse } from "@mastrojs/mastro";
export const POST = async (req: Request) => {
const data = await req.json();
const comment = await db.comments.insert(data);
return jsonResponse(comment);
};
Easy for beginners
Put your first website live without installing anything on your computer: The popular VS Code editor also runs in the browser.
Start with learning HTML and CSS. Then build a static blog and a to-do list app with JavaScript. Finally, serve a REST API.
Powerful for experienced developers
I’ve seen things you wouldn’t believe. Megabytes of JavaScript on fire in the browser. I watched towers of complex abstractions collapse upon themselves. All those websites will be lost in time, like tears in rain. Time to let them die.
To adopt Mastro incrementally, start using its html templates in your existing codebase before switching, or migrate route by route.
Install Mastro Docs ☆ Mastro on GitHub
Fast for everyone
Great UX: websites built with Mastro are fast – even on low-end devices on 3G.
Performance
Accessibility
SEO
Great DX: dev server starts instantly, and SSG is fast – e.g. for 500 markdown files:
| Mastro | 0.5s | 🏁 |
| 11ty | 0.7s | |
| Astro | 2.2s | |
| Next.js | 16.3s |
A foundation to build upon
The minimal Mastro core package doesn’t come “batteries included”, but it’s built to be extended.
Extensions / plugins
- Tiny libs in the
@mastrojsnamespace: - Install 3rd-party packages like:
- Kysely – type-safe SQL query builder
- Sveltia CMS – git-based CMS
Escape the frontend treadmill
Most JavaScript frameworks and complex build systems were designed to solve problems that no longer exist.
Join the community
We’re building an inclusive community, where people of all kinds of backgrounds and experience levels feel welcome and safe, and help each other. A place to ask questions and learn new things.
