Stage 3 · Build
Performance & Caching at Scale
Response Compression
Use gzip or brotli middleware, ETags, Cache-Control headers, and payload size budgets.
Why Compress
Compression reduces response size by 60-90%. For a JSON API returning 10KB responses, gzip reduces this to 2KB. This reduces bandwidth costs, improves latency, and saves client battery life.
Gzip Middleware
Brotli
Brotli achieves 15-25% better compression than gzip. It is supported by all modern browsers. Use it for static assets and API responses. The compression is slower but the bandwidth savings are significant.
ETags
Cache-Control
Payload Size Budgets
- Single resource: Under 10KB.
- List response: Under 100KB with pagination.
- File upload: Enforce max size with http.MaxBytesReader.
- File download: Stream large files with chunked transfer.
Responses under 1KB are not worth compressing. The overhead of compression outweighs the savings. Set a minimum size threshold in your compression middleware.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.