Brotli Compression
🗜️ Brotli Compression Extension
Section titled “🗜️ Brotli Compression Extension”Zuno includes built-in support for Brotli, a modern compression algorithm that offers better compression ratios than Gzip. This extension automatically compresses HTTP responses when the client supports it—reducing bandwidth usage and improving load times.
⚙️ Enabling Brotli Compression
Section titled “⚙️ Enabling Brotli Compression”To enable Brotli compression globally, register the extension using app.use()
:
app.use(compression());
Zuno will automatically:
- Detect if the client accepts
br
encoding - Compress the response body using Brotli
- Set the appropriate
Content-Encoding: br
header
🧪 Example
Section titled “🧪 Example”#include <zuno/zuno.hpp>
int main() {zuno::App app;
app.use(compression());
app.get("/data", [](Request& req, Response& res) { std::string largePayload = generateLargeJson(); res.send(largePayload);});
app.listen(3000);}
When a client sends:
GET /data HTTP/1.1Accept-Encoding: br
Zuno responds with:
HTTP/1.1 200 OKContent-Encoding: brContent-Type: application/json...compressed body...
⚠️ Notes
Section titled “⚠️ Notes”- Brotli is only applied to responses above a certain size threshold (e.g. 1KB)
- Binary files (e.g. images, videos) are typically excluded
- Clients that do not support Brotli will receive uncompressed responses
🧭 Best Practices
Section titled “🧭 Best Practices”- Use Brotli for large JSON, HTML, or text-based responses
- Avoid compressing already-compressed formats (e.g.
.zip
,.png
) - Monitor CPU usage in high-throughput environments
🧭 Next Steps
Section titled “🧭 Next Steps”Explore more extensions:
Zuno’s Brotli compression extension helps you deliver faster, leaner responses—without sacrificing clarity or control.