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! 🚀

typescript Article's
30 articles in total
Favicon
Unique Symbols: How to Use Symbols for Type Safety
Favicon
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)
Favicon
Teaching Large Language Models (LLMs) to do Math Correctly
Favicon
Angular Addicts #33: NgRx 19, using the Page Object Model in tests, Micro Frontends using Vite & more
Favicon
Share the state of a hook between components
Favicon
Swapable React context without breaking Rules of Hooks and your neck
Favicon
Matanuska ADR 010 - Architecture, Revisited
Favicon
Building a Robust Color Mixing Engine: From Theory to Implementation
Favicon
Automating Limit Orders on Polygon with TypeScript, 0x, and Terraform
Favicon
The Magic of useCallback ✹
Favicon
Building a Secure Authentication API with TypeScript, Node.js, and MongoDB
Favicon
"yup" is the new extra virgin olive oil
Favicon
Dynamic Routes in Astro (+load parameters from JSON)
Favicon
TypeScript Discord Bot Handler
Favicon
Form-based Dataverse Web Resources with React, Typescript and FluentUI - Part 2
Favicon
Converting JPA entities to Mendix
Favicon
lodash._merge vs Defu
Favicon
React Native With TypeScript: Everything You Need To Know
Favicon
100 Days of Code
Favicon
Ship mobile apps faster with React-Native-Blossom-UI
Favicon
Import JSON Data in Astro (with Typescript)
Favicon
How to write unit tests and E2E tests for NestJS applications
Favicon
Matanuska ADR 009 - Type Awareness in The Compiler and Runtime
Favicon
How to Build an Image Processor with React and Transformers.js
Favicon
Building an AI-Powered Background Remover with React and Transformers.js
Favicon
Exploring TypeScript Support in Node.js v23.6.0
Favicon
Observing position-change of HTML elements using Intersection Observer
Favicon
Breweries App
Favicon
Using LRU Cache in Node.js and TypeScript
Favicon
Build a Mac Tool to Fix Grammar Using TypeScript, OpenAI API, and Automator

Featured ones: