Alorel / shrink-ray

Node.js compression middleware
MIT License
177 stars 16 forks source link

Prefer zlib over zopfli for gzip? #39

Closed keeganstreet closed 5 years ago

keeganstreet commented 5 years ago

There was some nice work done in #36 to make iltorb and node-zopfli-es optional.

But zopfli-compat.js is preferring zopfli over zlib, and printing a warning if node-zopfli-es is not installed. zopfli may create gzip assets 5% smaller than zlib, but it is much slower (~100x).

Since shrink-ray-current is for use at runtime, speed is very important and I would prefer to use zlib not zopfli. This would be consistent with brotli-compat.js which is preferring zlib over iltorb. Would you be open to this change, or alternatively silencing the warning Module "node-zopfli-es" was unavailable?

Alorel commented 5 years ago

Hi and sorry for the late reply.

I would be more keen on silencing the error or adding a config option for it. node-zopfli does tend to offer better compression than zlib, even if slightly, and I believe it should be favoured in most scenarios where you're not trying to squeeze out the most CPU savings as possible.

keeganstreet commented 5 years ago

Hi Alorel, that's OK. If we add an option the change might look something like this:

Would you like a PR for this?

Alorel commented 5 years ago

Yep, that looks good. And yes, if you'd be willing to make a PR that'd be amazing, else I could get round to it over the weekend.

keeganstreet commented 5 years ago

I won't have time this week, but this is one of my next cards to pick up next week at work. No need to work on the weekend 😄

CodeIter commented 5 years ago

ok travis-ci test passed but COVERAGE DECREASED (-0.5%) TO 98.626% in file zopfli-compat.js

CodeIter commented 5 years ago

COVERAGE DECREASED (-0.3%) TO 98.898% in file zopfli-compat.js

//...
function getZopfliModule(useZopfliForGzip) {
    try {
      if(useZopfliForGzip){
        return require('node-zopfli-es');
      }
//...
Alorel commented 5 years ago

Thanks for the contribution, published as 4.1.0