diff --git a/packages/compression/readme.md b/packages/compression/readme.md index 73071c2..3d26a3a 100644 --- a/packages/compression/readme.md +++ b/packages/compression/readme.md @@ -1,4 +1,4 @@ -# @polka/compression [![npm](https://badgen.now.sh/npm/v/@polka/compression)](https://npmjs.org/package/@polka/compression) +# @polka/compression [![npm](https://badgen.now.sh/npm/v/@polka/compression)](https://npmjs.org/package/@polka/compression) [![licenses](https://licenses.dev/b/npm/%40polka%2Fcompression)](https://licenses.dev/npm/%40polka%2Fcompression) > An HTTP response compression middleware that supports native Gzip and Brotli. Works with [Polka][polka] and Express! @@ -28,51 +28,55 @@ polka() ## API -The `compression(options)` function returns a polka/express -style middleware of the form `(req, res, next)`. +### `compression(options?: Options): Middlware` -### Options +The `compression` function creates a Polka/Express-compatible middleware function. When no [`options`](#options) are defined, the defaults are used. - * @param {number} [options.threshold = 1024] Don't compress responses below this size (in bytes) - * @param {number} [options.level = -1] Gzip/Brotli compression effort (1-11, or -1 for default) - * @param {boolean} [options.brotli = false] Generate and serve Brotli-compressed responses - * @param {boolean} [options.gzip = true] Generate and serve Gzip-compressed responses - * @param {RegExp} [options.mimes] Regular expression of response MIME types to compress (default: text|javascript|json|xml) -#### threshold +## Options + +All options use a default value when a value is not defined. + +#### options.threshold Type: `Number`
Default: `1024` Responses below this threshold (in bytes) are not compressed. The default value of `1024` is recommended, and avoids sharply diminishing compression returns. -#### level +#### options.level Type: `Number`
Default: `-1` -The compression effort/level/quality setting, used by both Gzip and Brotli. The scale ranges from 1 to 11, where lower values are faster and higher values produce smaller output. The default value of `-1` uses the default compression level as defined by Gzip (6) and Brotli (6). +The compression effort/level/quality setting, used by both Gzip and Brotli. The scale ranges from `1` to `11`, where lower values are faster and higher values produce smaller output. + +The default value of `-1` uses the default compression level as defined by Gzip (`6`) and Brotli (`6`). -#### brotli +#### options.brotli Type: `boolean`
Default: `false` -Enables response compression using Brotli for requests that support it. This is not enabled by default because Brotli incurs more performance overhead than Gzip. +Enables response compression using Brotli for requests that support it. -#### gzip +Brotli incurs more performance overhead than Gzip, which is why it's not enabled by default. + +#### options.gzip Type: `boolean`
Default: `true` Enables response compression using Gzip for requests that support it, as determined by the `Accept-Encoding` request header. -#### mimes +#### options.mimes Type: `RegExp`
Default: `/text|javascript|\/json|xml/i` The `Content-Type` response header is evaluated against this Regular Expression to determine if it is a MIME type that should be compressed. -Remember that compression is generally only effective on textual content. + +> **NOTE:** Remember that compression is (generally) only effective on textual content. ## Support -Any issues or questions can be sent to the [Polka][polka] repo, but please specify that you are using `@polka/compression`. +Any issues or questions can be sent to the [Polka][polka] repository.
However, please specify that your inquiry is about `@polka/compression` specifically. ## License