Skip to content

Commit

Permalink
chore(compression): update readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Mar 7, 2024
1 parent 450973a commit 7745eb4
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/compression/readme.md
Original file line number Diff line number Diff line change
@@ -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!
Expand Down Expand Up @@ -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`<br>
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`<br>
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`<br>
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`<br>
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`<br>
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.<br>However, please specify that your inquiry is about `@polka/compression` specifically.


## License
Expand Down

0 comments on commit 7745eb4

Please sign in to comment.