http-compression is a lightweight Node.js library designed to add Gzip and Brotli compression capabilities to HTTP servers. Currently at stable version 1.1.3, it primarily functions as Express-style middleware but can also be integrated directly with Node.js's `http.createServer` primitives. The project maintains a steady, albeit infrequent, release cadence, with recent updates focused on dependency maintenance and minor feature enhancements. Key differentiators include its extremely small footprint (< 1kB) with no external dependencies, automatic detection of the best compression encoding (Gzip or Brotli) based on the `Accept-Encoding` header, and configurable compression levels, response size thresholds, and MIME type filtering. It requires Node.js version 18 or greater.
npm install http-compressionVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to integrate `http-compression` with a native Node.js HTTP server, applying custom compression settings for responses larger than a specified threshold.
Update your `level` option from a number (e.g., `level: 1`) to an object (e.g., `level: { brotli: 1, gzip: 1 }`).Ensure your Node.js environment is version 18 or greater. Upgrade Node.js if necessary.
If content is not being compressed, check the response body size. Adjust the `threshold` option if you need to compress smaller responses, e.g., `compression({ threshold: 0 })`.Verify the `Content-Type` header of the response. If you need to compress additional MIME types, customize the `mimes` option: `compression({ mimes: /text|javascript|\/json|xml|image\/svg\+xml/i })`.Use `import compression from 'http-compression';` for ESM or `const compression = require('http-compression');` for CommonJS to correctly obtain the factory function.Update the `level` option to be an object, e.g., `level: { brotli: 1, gzip: 1 }`. Refer to the API documentation for valid ranges for each algorithm.Check the response size (must be greater than `threshold`), the `Content-Type` header (must match `mimes`), and ensure the client sends `Accept-Encoding: gzip, deflate, br` header in the request.
No dependency data recorded yet.