dev-resources.site
for different kinds of informations.
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.
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:
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:
- Simplified Management: One server, multiple sites, each with its own domain
-
Cost Efficiency:
- Can run on minimal resources (256MB RAM!)
- Scale to zero when idle
- Volume-based pricing on Fly.io
-
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! π
Featured ones: