From aa3079a754826696796a0afa111d4aab27a2018c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20Ahlstr=C3=B6m?= <71292737+kahlstrm@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:59:45 +0200 Subject: [PATCH] perf!: reduce default brotli compression factor to 4, was before 11 (maximum) (#278) * perf(index): reduce default brotli compression factor to 4 * docs(readme): change default value of brotli quality --- README.md | 2 +- index.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 220813b..d2077ac 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ You can tune compression by setting the `brotliOptions` and `zlibOptions` proper brotliOptions: { params: { [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT, // useful for APIs that primarily return text - [zlib.constants.BROTLI_PARAM_QUALITY]: 4, // default is 11, max is 11, min is 0 + [zlib.constants.BROTLI_PARAM_QUALITY]: 4, // default is 4, max is 11, min is 0 }, }, zlibOptions: { diff --git a/index.js b/index.js index b824364..a29e710 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,12 @@ function processCompressParams (opts) { } const params = { - global: (typeof opts.global === 'boolean') ? opts.global : true + global: (typeof opts.global === 'boolean') ? opts.global : true, + /** + * Default of 4 as 11 has a heavy impact on performance. + * @see {@link https://blog.cloudflare.com/this-is-brotli-from-origin#testing} + */ + brotliOptions: { [zlib.constants.BROTLI_PARAM_QUALITY]: 4, ...opts.brotliOptions } } params.removeContentLengthHeader = typeof opts.removeContentLengthHeader === 'boolean' ? opts.removeContentLengthHeader : true