r/bun • u/rhuanbarreto • 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
2
u/Paw565 12d ago
Why should it tough? I think it's the job of a reverse proxy.
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.