惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
美团技术团队
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
V
V2EX
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
量子位
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Jina AI
Jina AI
月光博客
月光博客
L
LangChain Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building with Bun and Cosmic: The Fastest JavaScript Stac...
Tony Spiro · 2026-05-30 · via DEV Community

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

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

Step 2: Install the Cosmic SDK

bun add @cosmicjs/sdk

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!,
})

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)

bun run index.ts

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)
    },
  },
})

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.