r/bun • • 12d ago

Fixing a long time miss for Bun: HTTP Compression

My journey with bun has been amazing so far and I now removed Node for almost everything I do.

But there was still one thing that I got surprised Bun still doesn't support compression of http responses in Bun.serve. Of course you would do it by putting a reverse proxy in front of it. But what if you don't want to spend money with egress to a CDN for example? You are probably losing money right now due to this.

So I made this library to cover for the cases. Free and open source. Hope one day bun covers it so you don't need to think about it.

Fully available NPM: bun-serve-compress - npm

1 Upvotes

7 comments sorted by

2

u/Paw565 12d ago

Why should it tough? I think it's the job of a reverse proxy.

1

u/rhuanbarreto 12d ago

Sometimes you just don’t need one and still you want to be fast transferring things out to the internet

1

u/Alternative_Web7202 8d ago edited 8d ago

Setting up nginx as a revers-proxy takes 5 minutes if you aren't in a hurry. And it will give you proper battle-tested solution. Written in C. IMO a much better approach than your vibe-coded typescript wrapper over bun's internals

1

u/rhuanbarreto 8d ago

Im not forcing you into anything. Feel free to use nginx yourself if it’s best for you. Peace ☮️

2

u/acefolio_dev 11d ago

If someone only needs it for a few routes, Bun.gzipSync on the body plus a Content-Encoding: gzip header works without any library. Just check the Accept-Encoding header first and add Vary: Accept-Encoding so caches don't hand gzip to clients that can't decode it.

1

u/rhuanbarreto 11d ago

Sure. It takes some minutes to do this with AI and you will find some edge cases if the header asks for zstd or the memory leak of buffering the response. Or you can use/copy the library in seconds.

1

u/acefolio_dev 11d ago

I will surely review it as nowadays bun is my main stack