Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.prism.byescaleira.com/llms.txt

Use this file to discover all available pages before exploring further.

Compression Middleware

PrismCompressionMiddleware compresses response bodies using deflate compression — powered by Apple’s native Compression framework. No zlib, no third-party libraries.

Setup

Enable Compression
await server.use(PrismCompressionMiddleware())
When a client sends Accept-Encoding: deflate, responses are automatically compressed. The middleware adds the Content-Encoding: deflate header.

When to Use

Compression is most effective for:
  • JSON API responses (typically 60-80% reduction)
  • HTML pages
  • Large text payloads
Place compression middleware after caching middleware. You don’t want to compress the same cached response on every request.

Production Stack

With Caching
await server.use(PrismResponseCacheMiddleware(ttl: 300)) // Cache first
await server.use(PrismCompressionMiddleware())            // Then compress
Small responses (under ~150 bytes) may actually get larger after compression overhead. The middleware handles this gracefully — it only compresses responses above a meaningful threshold.