Performance

Compression

Reduce response size with Gzip and Deflate.

Compression

@bklarjs/compression uses Bun's native gzipSync and deflateSync to compress responses, reducing payload size by up to 70%.

Installation

bun add @bklarjs/compression
npm install @bklarjs/compression

Usage

It automatically negotiates content encoding with the client via the Accept-Encoding header.

import { compression } from "@bklarjs/compression";

// Apply globally
app.use(compression());

app.get("/big-json", (ctx) => {
  // This will be gzipped automatically if > 1KB
  return ctx.json(Array(1000).fill({ id: 1, name: "item" }));
});

Configuration

OptionDefaultDescription
threshold1024Minimum byte size to compress.
encodings['gzip', 'deflate']Supported algorithms.

On this page