Skip to content

compress

Negotiates Accept-Encoding and wraps the response stream through the best-matching compressor (Brotli, gzip, or deflate). Compression is skipped automatically for small bodies, non-compressible content types, and no-body status codes.

Pipeline stage: Cross-cutting (place before send)

import { compress } from "@centralping/ergo";
OptionTypeDefaultDescription
thresholdnumber1024Minimum body size in bytes before compression kicks in
encodingsstring[]['br', 'gzip', 'deflate']Supported encodings in priority order

The middleware modifies the response stream in-place (wrapping res.write and res.end). It does not add to the domain accumulator.

  • Status code is 204 or 304
  • Content-Type is non-compressible (binary, images, etc.)
  • Body is below threshold bytes
  • No acceptable encoding found in Accept-Encoding

None. Compression is silently skipped when conditions are not met.

import { compose, compress } from "@centralping/ergo";
const pipeline = compose(
compress({ threshold: 1024, encodings: ["br", "gzip"] }),
(req, res, acc) => ({
response: { body: largePayload },
}),
);

See the auto-generated compress API docs.