Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for brotli (br) compression in compress middleware #3543

Open
spaceemotion opened this issue Oct 21, 2024 · 6 comments
Open

Support for brotli (br) compression in compress middleware #3543

spaceemotion opened this issue Oct 21, 2024 · 6 comments
Labels
enhancement New feature or request.

Comments

@spaceemotion
Copy link

What is the feature you are proposing?

We're trying to modernize our app with Hono, but we'd like to use brotli compression for responses, instead of just gzip. Ssome of our calls can be a couple megabytes compressed, and the ratio between gzip and brotli is quite different.

From what I can tell, the list of supported compression algorithms is hard-coded:

const ENCODING_TYPES = ['gzip', 'deflate'] as const

* @param {'gzip' | 'deflate'} [options.encoding] - The compression scheme to allow for response compression. Either 'gzip' or 'deflate'. If not defined, both are allowed and will be used based on the Accept-Encoding header. 'gzip' is prioritized if this option is not provided and the client provides both in the Accept-Encoding header.

The node zlib package supports brotli, which should make it possible to implement it without an additional third party dependency.

Also, if there is a way to use the text mode for brotli for when the content is JSON or other text-only stuff would be great.

@spaceemotion spaceemotion added the enhancement New feature or request. label Oct 21, 2024
@EdamAme-x
Copy link
Contributor

EdamAme-x commented Oct 29, 2024

I think it's not bad since edge runtime etc. also supports this feature. (but, it's not supportted on service-worker as browser's features)
https://developers.cloudflare.com/workers/runtime-apis/nodejs/zlib/

@exoego
Copy link
Contributor

exoego commented Nov 2, 2024

Compress middleware relies on CompressionStream which does not support Brotli yet unfortunately.

Good news is that W3C TPAC is going to add Brotli to the standard.

whatwg/compression#34 (comment)
To summarise the discussion at TPAC 2024, we are going to add Brotli to the standard, but Chrome still won't be able to ship it for a while. It appears that Safari is ready to ship and Firefox is also positive on shipping.

@EdamAme-x
Copy link
Contributor

planning to ship! Looks good.

@yusukebe
Copy link
Member

yusukebe commented Nov 2, 2024

How about Zstandard? 😉

@spaceemotion
Copy link
Author

Brotli coming to the standards is good news indeed! I am guessing our only workaround for now is to clone the middleware, replace the bits and pieces to fit our node runtime, and wait until we can use the 'native' way?

@vuolter
Copy link

vuolter commented Nov 4, 2024

In the meantime I made my own plugin, with blackjack and hookers! 🤖

https://github.com/vuolter/hono-compress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

5 participants