Plugins

Compression

Official plugin — gzip response bodies for clients that send Accept-Encoding: gzip, with a size threshold and content-type matcher. Bun.serve does not compress on its own.

compression() gzips HTTP response bodies with the native Bun.gzipSync binding when the client advertises Accept-Encoding: gzip. Bun.serve never compresses on its own — without this plugin every byte goes over the wire raw, no matter how large the JSON.

Quick start

src/app.ts
import { oke } from "okengine";
import { compression } from "okengine/plugins";

export const app = oke({ name: "shop", env: "dev" }).plug(compression());

A client sending Accept-Encoding: gzip now receives Content-Encoding: gzip with a Vary: Accept-Encoding marker; a client that does not ask gets the untouched body.

Options

OptionTypeDefaultDoes
minSizenumber1024Bodies smaller than this pass through raw (gzip can grow tiny payloads)
matchRegExpJSON · +json · javascript · xml · text/*Which Content-Types are compressible
.plug(compression({ minSize: 0 })) // compress even tiny bodies (tests, debugging)

Notes

BehaviorDetail
NegotiationRuns only when Accept-Encoding allows gzip — gzip;q=0 is respected
Already encodedSkips responses that already carry Content-Encoding
no-transformSkips responses whose Cache-Control forbids transformation
Content-LengthDeleted after compression — stale lengths would corrupt the response
Non-HTTP triggersNo-op — nothing to compress outside HTTP

Runtime configuration

Thresholds and matchers can follow the database like every other official plugin — pass a configSource() as the options. See Plugins → Runtime configuration for the full contract.

Next

On this page