@youneed/server-middleware-compression
v0.1.0
Published
@youneed/server middleware: gzip/brotli response compression.
Readme
@youneed/server-middleware-compression
gzip/brotli the response when the client accepts it and the body is worth
compressing. It buffers the response (intercepting res.write/res.end), so it
suits typical JSON/text/HTML payloads rather than very large streams.
import { Application } from "@youneed/server";
import { compression } from "@youneed/server-middleware-compression";
Application()
.use(compression({ threshold: 1024 }))
.listen(3000, () => {});| option | default | meaning |
| --- | --- | --- |
| threshold | 1024 | minimum body size (bytes) before compressing |
| brotli | true | prefer brotli when the client supports it |
Sets
Content-Encoding, recomputesContent-Length, and appendsAccept-EncodingtoVary. Bodies belowthreshold, already-encoded responses, and non-compressible content types are passed through untouched.
