compression icon indicating copy to clipboard operation
compression copied to clipboard

Support for Brotli compression

Open joostdebruijn opened this issue 9 years ago • 19 comments

Is it an idea to add Brotli compression for https-requests to this module? Now support for Brotli has landed in the developer channels of Firefox and Chrome it is very likely that a significantly amount of clients will have support for this enabled in the very near future. So, it is maybe a good idea to support it in this module too.

I’m not (yet) very experienced with building modules for Node, but if there is anything I can help with, please let me know.

joostdebruijn avatar Jan 24 '16 13:01 joostdebruijn

Hi! This was discussed before in https://github.com/expressjs/compression/issues/59 if you want to read the prior discussion.

The answer is that we certainly can, but for it to be built-in here, we need the support either added to Node.js core or a pure-JS library.

Barring that, another option is to make this module flexible and allow for alternative user-defined encodings. There was the PR https://github.com/expressjs/compression/pull/62 but it was never completed due to a disagreement between the author and myself over a feature I wanted to be supported.

dougwilson avatar Jan 24 '16 15:01 dougwilson

The performance of brotli is something that should be kept in mind.

Some previous tests:

  • https://blog.cloudflare.com/results-experimenting-brotli/
  • https://www.opencpu.org/posts/brotli-benchmarks/

brotli isn't necessarily always more efficient than gzip. brotli's biggest advantage is that at higher compression levels, at the cost of compression time, you can get compression ratios beyond what you can do even by using zopfli.

So you don't really get an advantage from using zopfli or brotli for dynamic content. They work best when you can wait a few extra seconds to let the compressor do more work.

For most people this means making a .gz file (using zopfli) and a .bro file with brotli during your build step and using the pre-compressed files instead of dynamically compressing with either.

dantman avatar Feb 01 '16 15:02 dantman

dougwilson, maybe this can help: A JavaScript port of the Brotli compression algorithm https://github.com/devongovett/brotli.js

LeandroFavero avatar Feb 12 '16 22:02 LeandroFavero

Note that the above port of Brotli doesn't support streaming yet. People interested in brotli and zopfli in the meantime may want to have a look at https://github.com/aickin/shrink-ray.

passcod avatar May 25 '16 22:05 passcod

@dantman At level 4, Brotli uses less CPU AND compresses better than gzip - here's the results of a test using the top 1000 URLs on the internet: https://blogs.akamai.com/2016/02/understanding-brotlis-potential.html

mikemaccana avatar Apr 04 '17 12:04 mikemaccana

It looks like Node.js is discussing adding support ad a built-in https://github.com/nodejs/node/issues/18964 which should make it trivial to add to this module.

dougwilson avatar Mar 11 '18 04:03 dougwilson

This library supports streaming - https://github.com/MayhemYDG/iltorb#stream (native package though, maybe make it an optional dep?)

If the maintainers are interested I can send a PR, let me know.

yocontra avatar Dec 18 '18 18:12 yocontra

Built in support in Node landed 2 days ago: https://github.com/nodejs/node/pull/24938

voxpelli avatar Jan 07 '19 18:01 voxpelli

Node 11.7.0 has been released with brotli support 🎉

adrienharnay avatar Jan 18 '19 15:01 adrienharnay

PR #150

dougwilson avatar Jan 18 '19 16:01 dougwilson

Hey guys, when are you going to release the new version with support for brotli? I'm already using your lib, and i didn't wanted to change to another, because your lib is working fine in my project.

camillegrings avatar Mar 25 '19 17:03 camillegrings

I submitted a PR https://github.com/expressjs/compression/pull/156 since there was not progress on the other one.

patrickmichalina avatar Jun 07 '19 21:06 patrickmichalina

Is there any reason Patrick's PR from above is still waiting for a merge? I'm running on 10.16 at the moment and would love to be able to turn brotli on - I can't see anything obvious holding up the release of that option via the PR.

KB1RMA avatar Aug 07 '19 16:08 KB1RMA

It seems like a duplicate of https://github.com/expressjs/compression/pull/150 and doesn't even address the issues that were brought up in that issue.

dougwilson avatar Aug 07 '19 17:08 dougwilson

Ah I missed that PR, sorry. Looks like it addresses the testing well but not the options.

KB1RMA avatar Aug 10 '19 21:08 KB1RMA

I can look into the options portion as well.

patrickmichalina avatar Sep 09 '19 15:09 patrickmichalina

Yet another PR #173

nicksrandall avatar Sep 15 '20 16:09 nicksrandall