Recommended Strategy
For a low-traffic API, you should combine JSON minification with Brotli compression. Minification provides a baseline reduction with negligible CPU cost, while Brotli delivers the most significant reduction in transferred bytes. Streaming JSON parsers are generally unnecessary for low-traffic endpoints unless your individual payloads are massive (multi-megabyte), as they solve memory pressure rather than bandwidth or operational costs.
Technical Trade-offs
Minification
Minification is a structural change to the payload. It removes whitespace and comments, which reduces the raw string size before it ever reaches the compression layer.
- CPU Impact: Negligible. Most JSON serializers (e.g.,
JSON.stringify() in Node.js or json.dumps() in Python) minify by default.
- Debugging: Makes raw network logs harder to read. However, this is easily mitigated by using browser developer tools or CLI tools (like
jq) that automatically pretty-print JSON.
Brotli Compression
Brotli is a transport-layer encoding. It identifies repeating patterns in the text to shrink the payload significantly more than minification alone.
- CPU Impact: Higher than minification, but on low-traffic endpoints, the total CPU load remains insignificant. The primary cost is the initial compression of the response.
- Compatibility: Requires HTTPS. Modern clients support it via the
Accept-Encoding: br header. If a client does not support Brotli, the server typically falls back to Gzip or uncompressed identity encoding.
Implementation Steps
- Enable Minification: Ensure your API serializer is not adding "pretty-print" indentation in production environments.
- Enable Brotli: Configure your web server (e.g., Nginx, Caddy) or API gateway to use Brotli compression.
- Verify Headers: Confirm the server responds with
Content-Encoding: br when the client sends Accept-Encoding: br.
Verification
You can verify the actual bandwidth savings using curl:
curl -H "Accept-Encoding: br" -I https://api.yourdomain.com/endpoint
Check the Content-Length (uncompressed size) versus the actual bytes transferred in your network monitor to see the efficiency gain.
Missing Diagnostic Detail
What is the average size of your largest JSON response? If payloads are consistently under 1KB, the overhead of compression headers may negate the benefits of Brotli.