gzipper icon indicating copy to clipboard operation
gzipper copied to clipboard

Request --min-gain 1024

Open micheartin opened this issue 5 years ago • 0 comments

The Brotli plugin for Webpack has an interesting minRatio parameter: https://www.npmjs.com/package/brotli-webpack-plugin

minRatio: Only assets that compress better that this ratio are processed. Defaults to 0.8.

We might add the option --min-ratio {value}. Note: the option --min-ratio 1 is the same as --remove-larger. This option applies to Gzip and to Brotli compressors.

However, we can also think further:

  • What about large files? Let's say 800 KB compressed file (original size is 1000 KB). The value --min-ratio 0.8 excludes this compressed file and the web server does not save 200 KB in local cache and bandwidth.

  • What about tiny files? Let's say 79 bytes compressed file (original size is 100 bytes). The value --min-ratio 0.8 keeps this compressed file, but for a ridiculous gain of 21 bytes while consuming CPU for decompression on the client side. Thanks to the option --threshold 1000, we can prevent this corner case.

Therefore, I propose the option:

--min-gain {bytes}

This option can also avoid using the options --remove-larger and --threshold {xxx}:

  1. --min-gain 1 (1 byte) is the same as --remove-larger
  2. --min-gain 100, by design, excludes all files smaller than 100 bytes

To clarify this last point, --min-gain 100 also excludes some files larger than 100 bytes: the smaller files that are not well compressed. For example, a PNG file of 200 KB compressed to 101 KB will be excluded by --min-gain 100.

From my personal point of view, --min-gain is more interesting than --threshold. For example, --threshold 1000 may exclude an index.html (990 bytes) and its index.html.br (80 bytes). It looks better to use something like --min-gain 900.

Default value 0 (or -1) --> Disable this option.

It is up to you whether you implement --min-ratio or --min-gain or both. However, in my personal opinion, --min-gain is superior to --remove-larger, --threshold and --min-ratio. I think --min-ratio is not necessary if --min-gain is implemented.

micheartin avatar Apr 20 '21 08:04 micheartin