oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.82k stars 2.56k forks source link

gzip compression of http responses #2726

Open jakeg opened 1 year ago

jakeg commented 1 year ago

What is the problem this feature would solve?

Currently all http responses are uncompressed.

What is the feature you are proposing to solve the problem?

Would be good to enable gzip compression for http responses.

@Jarred-Sumner says "this is a flag that the HTTP server Bun uses internally supports, but we haven't exposed it yet"

What alternatives have you considered?

No response

jakeg commented 8 months ago

Any progress on this? It's such an easy win for reducing bytes over the wire.

icflorescu commented 5 months ago

+1

andirkh commented 5 months ago

+1

andirkh commented 5 months ago

I think I have a workaround solution for anyone who need gzip-compression over http response.

Given: you want to return an html in the response that can be consumed by browser.

so this my simple code :

Bun.serve({
  fetch(req) {   
    const compressed = Bun.gzipSync(htmlString);
    return new Response(compressed, { 
      headers: { 
        'Content-Type': 'text/html',
        'Content-Encoding': 'gzip' 
      }
    })
  }
})