1. @polka/compression
Fast gzip+brotli compression middleware for polka & express with zero dependencies.
@polka/compression
Package: @polka/compression
Created by: lukeed
Last modified: Thu, 07 Mar 2024 22:32:04 GMT
Version: 1.0.0-next.25
License: MIT
Downloads: 2,850
Repository: https://github.com/lukeed/polka

Install

npm install @polka/compression
yarn add @polka/compression

@polka/compression npm licenses

An HTTP response compression middleware that supports native Gzip and Brotli. Works with Polka and Express!

Install

$ npm install --save @polka/compression

Usage

 const polka = require('polka');
const compression = require('@polka/compression');

polka()
  .use(compression({ /* see options below */ }))
  .use((req, res) => {
    // this will get compressed:
    res.end('hello world!'.repeat(1000));
  })
  .listen();

API

compression(options?: Options): Middlware

The compression function creates a Polka/Express-compatible middleware function. When no options are defined, the defaults are used.

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.

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).

options.brotli

Type: boolean

Default: false

Enables response compression using Brotli for requests that support it.

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.

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.

NOTE: Remember that compression is (generally) only effective on textual content.

Support

Any issues or questions can be sent to the Polka repository.
However, please specify that your inquiry is about @polka/compression specifically.

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin