compression-next is a Node.js middleware designed for compressing HTTP responses, offering support for `deflate`, `gzip`, and `brotli` encodings. Currently at version 1.0.3, this package originated as a pragmatic fork to provide immediate `brotli` compression functionality, addressing a long-standing feature request within the `expressjs/compression` project. Its release cadence is reactive, likely responding to updates in Node.js's native `zlib` module or the upstream `expressjs/compression` project. A primary differentiator is its readily available `brotli` support, a feature not present in the mainstream `expressjs/compression` at the time of its inception. Developers using this library should be aware of its temporary nature, with the expectation to transition back to the core `expressjs/compression` once `brotli` is officially integrated there. It integrates seamlessly with popular Node.js web frameworks like Express.
npm install compression-nextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `compression-next` with an Express application, applying compression to HTTP responses. It shows basic usage with options like compression level and a custom filter.
Ensure your Node.js environment is at least v11.7.0 or v10.16.0 to leverage Brotli compression. Refer to 'engines' field in package.json.
Monitor the `expressjs/compression` repository for Brotli integration. Once available, plan to migrate your application to the official package for long-term stability and maintenance.
If compression is desired, ensure that the `Cache-Control` header does not include `no-transform`. Adjust server or proxy configurations if this header is being set unintentionally.
Always set an appropriate `Content-Type` header for your responses. For custom compression logic, provide your own `filter` function in the middleware options.
For ESM, use `import compression from 'compression-next';`. For CommonJS, use `const compression = require('compression-next');`. Do not use named imports like `import { compression } from 'compression-next';`.Upgrade Node.js to v11.7.0 / v10.16.0 or newer. Verify the client's `Accept-Encoding` header includes 'br'. Ensure the response `Content-Type` is recognized as compressible or provide a custom `filter` function.
Inspect HTTP response headers for `Cache-Control: no-transform`. Check `res.getHeader('Content-Type')` to ensure it's a compressible type. Debug any custom `filter` function logic to ensure it returns `true` when compression is desired.