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/compressionnpm install @bklarjs/compressionUsage
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
| Option | Default | Description |
|---|---|---|
threshold | 1024 | Minimum byte size to compress. |
encodings | ['gzip', 'deflate'] | Supported algorithms. |