DEV Community

Cover image for Building with Bun and Cosmic: The Fastest JavaScript Stack in 2026
Tony Spiro
Tony Spiro

Posted on • Originally published at cosmicjs.com

Building with Bun and Cosmic: The Fastest JavaScript Stack in 2026

Originally published on the Cosmic blog.

Bun v1.3 is the fastest JavaScript runtime you can use right now. Cosmic's REST API returns content in under 100ms. Put them together and you get a full-stack setup that's faster at every layer: cold starts, package installation, HTTP requests, and content delivery.

This is a practical tutorial. You'll set up a Bun project, pull content from Cosmic using the JavaScript SDK, and see why this combination is the right default for JavaScript developers building content-heavy apps in 2026.

Bun is also actively rewriting core internals in Rust, doubling down on raw performance and memory safety. This isn't just an optimization story: it signals a long-term commitment to speed as a first-class priority.

Why Bun in 2026

Bun started as a fast alternative to Node.js, but in December 2025 it was acquired by Anthropic, which is now betting on it as the runtime infrastructure powering Claude Code and the Claude Agent SDK. That acquisition signals something: the fastest JavaScript runtime is also where serious AI tooling is heading.

Bun is built on JavaScriptCore (the engine that powers Safari) and written in Zig. It ships as a single binary that includes a runtime, package manager, bundler, and test runner. In practice this means:

  • Install speed: Bun installs packages up to 25x faster than npm. With v1.3.14's global store, warm reinstalls are 7x faster again.
  • Startup time: Cold start times are significantly lower than Node.js, particularly for TypeScript projects where Bun transpiles natively without a separate build step.
  • Async/await performance: Bun v1.3.7 shipped 35% faster async/await. v1.3.6 brought 15% faster async/await on top of that.
  • Built-in tooling: No tsconfig.json gymnastics, no separate transpiler, no test framework to install.

Bun v1.3 (released October 2025) added zero-config frontend development, a unified SQL API, and a built-in Redis client. As of v1.3.14, it includes a built-in image processing API, HTTP/3 support, and 7x faster warm installs. It's not a prototype anymore: Vercel added native Bun runtime support in October 2025.

Why Cosmic as the Content Layer

Cosmic is an API-first headless CMS. Your content lives in Cosmic's CDN-backed infrastructure and is available via a REST API and JavaScript SDK.

Key performance characteristics:

  • Cached API requests are served from a global CDN. Sub-100ms response times in most regions.
  • The JavaScript SDK is typed and tree-shakeable.
  • No CMS server to run, no database to provision. You write frontend code and fetch content.

For Bun specifically, this matters because Bun's fast startup time is only useful if your data layer doesn't become the bottleneck. Cosmic's cached REST API is fast enough that it doesn't.

Setting Up the Stack

Prerequisites

Step 1: Create a Bun project

bun init
Enter fullscreen mode Exit fullscreen mode

Bun creates package.json, tsconfig.json, and an entry point. No additional configuration needed.

Step 2: Install the Cosmic SDK

bun add @cosmicjs/sdk
Enter fullscreen mode Exit fullscreen mode

Installs in roughly 200ms on a warm cache.

Step 3: Create your Cosmic client

// lib/cosmic.ts
import { createBucketClient } from '@cosmicjs/sdk'

export const cosmic = createBucketClient({
  bucketSlug: process.env.COSMIC_BUCKET_SLUG!,
  readKey: process.env.COSMIC_READ_KEY!,
})
Enter fullscreen mode Exit fullscreen mode

That's the entire setup. No ORM, no connection pool.

Step 4: Fetch content

import { cosmic } from './lib/cosmic'

const { objects: posts } = await cosmic.objects
  .find({ type: 'posts' })
  .props(['title', 'slug', 'metadata'])

console.log(posts)
Enter fullscreen mode Exit fullscreen mode
bun run index.ts
Enter fullscreen mode Exit fullscreen mode

No compilation step. Bun runs TypeScript directly. On a warm cache the Cosmic API call returns in under 100ms.

Building a Bun HTTP Server with Cosmic

Bun has a built-in HTTP server (Bun.serve) that's significantly faster than Express on Node.js:

import { cosmic } from './lib/cosmic'

Bun.serve({
  port: 3000,
  routes: {
    '/api/posts': async () => {
      const { objects } = await cosmic.objects
        .find({ type: 'posts' })
        .props(['title', 'slug', 'metadata'])
      return Response.json(objects)
    },
  },
})
Enter fullscreen mode Exit fullscreen mode

No framework, no middleware setup, no boilerplate.

Performance Reality Check

  • Bun startup time: ~5ms on modern hardware. Node.js + ts-node is typically 200-500ms.
  • Cosmic cached API response: Under 100ms from most regions for cached content.
  • Bun package install: First install of a medium-sized project takes 5-10 seconds with Bun vs 30-60 seconds with npm.

None of these numbers require you to do anything special. Install Bun, use @cosmicjs/sdk, and you get them automatically.

Why This Matters in 2026

A few things converged to make this stack compelling right now:

  • Bun joined Anthropic in December 2025. The runtime that powers Claude Code is the same one you can use for your projects.
  • Bun 1.3 added zero-config frontend support.
  • Vercel added native Bun runtime support in October 2025.
  • The Cosmic REST API is genuinely fast: CDN-backed, sub-100ms cached responses.

The practical result: a Bun + Cosmic stack is faster to set up, faster to install, faster to run, and delivers fast content. There's no trade-off to evaluate here.

Get Started

Sign up for Cosmic free (no credit card required), create a bucket, add a content type, and follow the setup steps above. You'll have a working content API in under 10 minutes.

Want to talk through your specific use case? Book a 30-minute intro with Tony.

Top comments (0)