DEV Community

Cover image for PrinceJS 2.1: The 4.8kB Bun Framework Just Got Even Faster (21.7k req/s) and Fully Loaded
Little Prince
Little Prince

Posted on

PrinceJS 2.1: The 4.8kB Bun Framework Just Got Even Faster (21.7k req/s) and Fully Loaded

Hey DEV! đź‘‹

A few months ago, I shared that I—a 13-year-old developer from Nigeria—built a Bun framework that outperformed Express. The response was incredible, and the feedback even better.

Today I'm back with PrinceJS v2.1, and I've got some updates to share. The old numbers floating around (19k req/s, 2.4kB gzipped) are outdated. Here's the real story.

⚡ Updated Benchmarks (oha -c 100 -z 30s on Windows 10)

After the community pointed out I should use oha instead of bombardier, I re-ran all tests. The results put PrinceJS firmly in the top three Bun frameworks:

Framework Req/s Total Requests (30s)
Elysia 25,312 759k
Hono 22,124 664k
PrinceJS 21,748 653k
Express 9,325 280k

âś… PrinceJS is 2.3Ă— faster than Express.

âś… Still comfortably in the top 3.

📦 True Bundle Size (Not 97kB!)

I also corrected the size reporting. PrinceJS is tree‑shakeable and has zero dependencies. The real numbers:

  • Minified: 14.7kB
  • Minified + Gzipped: 4.8kB
  • Download on Slow 3G: 97ms
  • Download on Emerging 4G: 6ms

That tiny footprint makes it perfect for edge functions, serverless, and any environment where every kilobyte counts.

✨ What's New in v2.1?

Version 2.1 isn't just a performance fix—it's a massive feature drop. PrinceJS is now a batteries-included super-framework that stays tiny.

📖 OpenAPI + Scalar Docs (Auto‑magical)

const api = app.openapi({ title: "My API", version: "1.0.0" }, "/docs");
api.route("GET", "/users/:id", {
  schema: { response: z.object({ id: z.string() }) },
}, (req) => ({ id: req.params.id }));
// → GET /docs serves a beautiful Scalar UI playground
// → GET /docs.json serves raw OpenAPI spec
Enter fullscreen mode Exit fullscreen mode

🎣 Lifecycle Hooks (Observability built-in)

app.onRequest((req) => { /* ... */ });
app.onBeforeHandle((req, path, method) => { /* ... */ });
app.onAfterHandle((req, res) => { /* ... */ });
app.onError((err, req) => { /* ... */ });
Enter fullscreen mode Exit fullscreen mode

🔌 Plugin System

const myPlugin: PrincePlugin = (app, opts) => { ... };
app.plugin(myPlugin, { prefix: "/api" });
Enter fullscreen mode Exit fullscreen mode

🌍 Deploy Adapters

Deploy anywhere with a single import:

  • Vercel Edge (princejs/vercel)
  • Cloudflare Workers (princejs/cloudflare)
  • Deno Deploy (princejs/deno)
  • Node.js (native or Express) (princejs/node)

🍪 Cookies & IP Detection

app.get("/profile", (req) => ({
  sessionId: req.cookies?.sessionId,
  clientIp: req.ip,
}));
Enter fullscreen mode Exit fullscreen mode

đź§° Helpers Galore (No Dependencies!)

  • cron() – schedule jobs natively
  • cache() – in‑memory TTL cache
  • upload() – handle file uploads
  • sse() – server‑sent events
  • db.sqlite() – SQLite ORM powered by Bun
  • jwt(), session(), compress() – all in middleware

⚛️ JSX/SSR (Without React)

import { Html, Body, H1, render } from "princejs/jsx";
app.get("/", () => render(Html(Body(H1("Hello PrinceJS!")))));
Enter fullscreen mode Exit fullscreen mode

🔒 End‑to‑End Type Safety

Define a contract once and get full autocomplete on the client:

import { createClient } from "princejs/client";
const client = createClient<ApiContract>("http://localhost:3000");
const user = await client.get("/users/:id", { params: { id: "42" } });
// user.name is typed as string âś…
Enter fullscreen mode Exit fullscreen mode

🚀 Quick Start

bun add princejs
Enter fullscreen mode Exit fullscreen mode
import { prince } from "princejs";
const app = prince();
app.get("/", () => ({ hello: "world" }));
app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

📚 Why PrinceJS?

Most "fast" frameworks are bare‑bones routers. PrinceJS gives you everything you need for production—OpenAPI, cron, SQLite, WebSockets, JSX, adapters—all in 4.8kB gzipped and zero dependencies.

I built this because I wanted a framework that was both tiny and powerful. A framework that a 13‑year‑old in Nigeria could use to build world‑class apps without pulling in hundreds of dependencies.

đź”— Links


Built with ❤️ in Nigeria.

Try it out and let me know what you build! 🚀

Top comments (0)