oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.37k stars 2.78k 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 1 year ago

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

icflorescu commented 9 months ago

+1

andirkh commented 9 months ago

+1

andirkh commented 9 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' 
      }
    })
  }
})
jakeg commented 2 months ago

Any official support for this on the way?