9.1
Datastar Brotli Compression
| (require datastar-brotli) | package: datastar-brotli |
This package provides Brotli compression support for the datastar SDK. Pass the resulting write profile to datastar-sse via the #:write-profile keyword argument to compress SSE events on the wire. The SDK automatically falls back to uncompressed output when the client does not advertise br in its Accept-Encoding header.
1 Usage
(require datastar datastar-brotli) (define brotli-profile (make-brotli-write-profile #:quality 5)) (define (handler req) (datastar-sse req (lambda (sse) (patch-elements sse "<div id=\"out\">Hello, compressed!</div>")) #:write-profile brotli-profile))
2 API
procedure
(make-brotli-write-profile [ #:quality quality #:window window #:mode mode]) → write-profile? quality : (integer-in 0 11) = 5 window : (integer-in 10 24) = 22 mode : mode/c = BROTLI_MODE_TEXT
Creates a write-profile? that compresses SSE output with Brotli.
quality —
Compression level from 0 (fastest) to 11 (smallest). Default 5 is a reasonable balance for streaming. window —
Sliding window size from 10 to 24. Larger values may improve compression at the cost of memory. mode —
One of BROTLI_MODE_GENERIC, BROTLI_MODE_TEXT, or BROTLI_MODE_FONT. Use BROTLI_MODE_TEXT (the default) for SSE, which is UTF-8 text.
value
Generic mode, no assumptions about content type. Re-exported from libbrotli.
value
Text mode, optimized for UTF-8 input. Re-exported from libbrotli.
value
Font mode, optimized for WOFF 2.0 fonts. Re-exported from libbrotli.