Skip to content

Body Compression Plugin

Body Compression Plugin compresses response bodies to reduce bandwidth usage and improve performance for clients that support compression.

Import

Depending on your adapter, import the corresponding plugin:

ts
import { BodyCompressionHandlerPlugin } from '@orpc/server/node'
import { BodyCompressionHandlerPlugin } from '@orpc/server/fetch'

Setup

Add the plugin to your handler:

ts
const handler = new RPCHandler(router, {
  plugins: [
    new BodyCompressionHandlerPlugin(),
  ],
})

INFO

The handler can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or a custom one.

Learn More

For implementation details, see the fetch adapter source code and the node adapter source code.

Released under the MIT License.