Logo

dev-resources.site

for different kinds of informations.

Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)

Published at
1/15/2025
Categories
javascript
webdev
typescript
docker
Author
pmbanugo
Author
8 person written this
pmbanugo
open
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)

Static sites are a thing of beauty and simplicity. They're fast, secure, and easy to manage. The JAMStack movement help made it popular (after SPAs) and static site builders like Hugo and Eleventy are making it simple to build websites in this manner. I dare not mention Astro because it's the new kid making building static sites cooler than ever.

Static sites are cool, you get it. But how do you host them? There are plenty of options like;

  • Using AWS S3 and CloudFront
  • Using static site hosting providers like Netlify or even host with GitHub Pages.

These options are good but as with most things, there are different people with different needs and preferences. There are people who like to self-host their own things, and there are some who manage a lot of projects and want a flexible way to manage and customise them. If you're one of those people, you'll love bun-tastic.

What is bun-tastic?

bun-tastic is a high-performance static site server that's designed to be fast, flexible, and easy to use. It's built to run on Bun(a fast and modern JavaScript runtime) and its S3 API. It uses any S3-compatible object storage to store the site files. However, I'd recommend you use Tigris because it can cache objects globally, making it faster for you to access them from anywhere in the world. Think of it like AWS S3 and CloudFront combined, but in this case you don't have to pay extra for global cache or worry about setting up an extra tool.

If you want to deploy in multiple regions so that your users can have lower latency, I'd Fly.io because scaling to zero and multi-region deployment is as simple as running a single command.

Using those technologies, this is what you get out of bun-tastic:

  • Serve multiple static websites from one application
  • Smart path handling with automatic index.html resolution
  • Globally fast and automatic TLS certificates (if using Fly)
  • Easy configuration through JSON
  • HTTP/3 support (via Fly)
  • Brotli & zstd compression support
  • Built-in monitoring with Grafana dashboard on Fly
  • Built on Bun's native S3 client and web server, thereby benefiting from Bun's fast performance
  • It uses zero dependency and can run on a single machine with 256MB RAM

The Speed Factor πŸš€

I'll say it again - it's fast! Here's a load test on a shared VM with 256MB RAM, 1 vCPU, deployed to the Stockholm (Sweden) region on fly.io.

Load testing demonstration as GIF

Most responses come in under 100ms, for a response that weighs 6KiB. That's fast! Here's a still image so you can see the numbers clearly:

Load testing image results

More About The Tech Stack ⚑

By now you know that the secret sauce is a combination of modern tech that works together beautifully:

Bun's Native Powers

Built on Bun's native S3 client and web server, we're getting incredible performance benefits right out of the gate. Zero dependencies mean less overhead and faster execution.

HTTP/3 + Smart Compression

Here's what you get if you deploy to Fly:

  • HTTP/3 support for modern web performance
  • Brotli & zstd compression keeping things lean
  • automatic TLS certificates for secure connections
  • Fly.io's global compute for fast and reliable global distribution

Globally Distributed Object Storage

  • Tigris provides global caching out of the box
  • Objects cached closer to users = faster subsequent requests

Why You Might Need This πŸ€”

If you're a design/dev agency, freelancer, or just someone managing multiple sites, here's why bun-tastic might be your new best friend:

  1. Simplified Management: One server, multiple sites, each with its own domain
  2. Cost Efficiency:
    • Can run on minimal resources (256MB RAM!)
    • Scale to zero when idle
    • Volume-based pricing on Fly.io
  3. Complete Control:
    • Configure redirect/rewrite rules
    • Add custom middleware
    • Set up authentication per domain if you want to share it with clients.

This might not be the cheapest option because you have to pay for servers. If you want cheap, look else where. But if you want control, flexibility, and performance, bun-tastic is a great option.

I imagine that using volume-based pricing and auto-scale to zeo on Fly, you can get a lot with just a few bucks a month. Currently cheapest machine with 256MB RAM is around $3.xx/month on a volume license (at least the US regions). If your customers are in the US, and you serve infrequest requests, you can get away with a lot of sites for a few bucks a month.

FAQs

"Why not just use traditional static hosting?"

Traditional hosting is fine, but bun-tastic gives you more control and flexibility. Want to add authentication to specific routes? Need custom redirect rules? Want to serve content to specific users?

You can do all that and more.

"Is it more expensive to self-host?"

It depends on your scale. For a single low-traffic site, traditional hosting might be cheaper. But if you're managing many sites or dealing with higher traffic, the combination of Tigris and Fly's volume-based pricing can actually save you money or give you more speed.

"Can I use any S3-compatible storage?"

Absolutely! While we recommend Tigris for its global caching benefits, any S3-compatible storage will work just fine.

What's Next?

Check out the code and set up instructions on GitHub. Don't forget to star the repo if you find it useful!

This is just the beginning and here's what I plan to add to it soon:

  • CLI for simplified site uploads
  • 103 Early Hints support
  • More caching semantics
  • Multi-core configuration
  • Bot request blocking (I wonder if this makes sense to add or leave to CDNs)

There you go. Self-hosting static sites on your own terms. Bun-tastic! πŸš€

javascript Article's
30 articles in total
JavaScript is a versatile language for web development, enabling interactive and dynamic user experiences across all major browsers.
Favicon
7 Developer Tools That Will Boost Your Workflow in 2025
Favicon
Creating a live HTML, CSS and JS displayer
Favicon
Designing for developers means designing for LLMs too
Favicon
Unique Symbols: How to Use Symbols for Type Safety
Favicon
Flutter vs React Native in 2025: A Comprehensive Comparison
Favicon
How To Build Beautiful Terminal UIs (TUIs) in JavaScript 2: forms!
Favicon
[Boost]
Favicon
CΓ³mo Iniciar y Crecer como Desarrollador Frontend en 2025
Favicon
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)
Favicon
My React Journey: Project
Favicon
How to Use JavaScript to Reduce HTML Code: A Simple Example
Favicon
Easy Discount Calculation: Tax, Fees & Discount Percentage Explained
Favicon
GraphQL Transforming API Development
Favicon
7 Mistakes Developers Make When Learning a New Framework (and How to Avoid Them)
Favicon
Why Is Everyone Unhappy With JavaScript? | State of Javascript 2024 Survey
Favicon
Decreasing server load by using debouncing/throttle technique in reactjs
Favicon
What is Next Js: A Beginner's guide to Next Js
Favicon
Angular Addicts #33: NgRx 19, using the Page Object Model in tests, Micro Frontends using Vite & more
Favicon
Debugging Adventure Day 1: What to Do When Your Code Doesn’t Work
Favicon
10 Must-Bookmark Open Source Projects for Developers
Favicon
Build a Secure Password Generator with Javascript
Favicon
Everything you need to know about load testing concurrent users
Favicon
forms in the terminal w/ JavaScript? if you love Terminal UI's check this out!
Favicon
340+ Websites every developer should know
Favicon
Learning Vue
Favicon
Test Scenarios vs. Test Cases: Understanding the Differences
Favicon
LeetCode Challenge: 290. Word Pattern - JavaScript Solution πŸš€
Favicon
Understanding Node.js Cluster: The Core Concepts
Favicon
Speed Up Your Frontend Development 10x with These Mock Tools πŸš€
Favicon
[Boost]

Featured ones: