Content negotiation lets client and server agree on the best representation for data exchange.

Common negotiation dimensions

  • Media type (JSON, XML, HTML)
  • Language (English, Spanish, etc.)
  • Encoding/compression (gzip, br, deflate)

Request-side preference headers

  • Accept
  • Accept-Language
  • Accept-Encoding

Example:

GET /api/content HTTP/1.1
Accept: application/json
Accept-Language: es
Accept-Encoding: gzip, br

Server may respond in Spanish JSON and compressed form, depending on capabilities.

Why this matters

Same endpoint can adapt representation to client capabilities without changing core business logic.

Compression focus

For large payloads, compression dramatically reduces transfer size.

Example response:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip

The browser/client decompresses automatically and receives original content.

This reduces:

  • network transfer time
  • bandwidth usage
  • user-perceived latency

Design considerations

  • Enable compression for large text-based responses (JSON, HTML, CSS, JS)
  • Avoid compressing already compressed binaries unless necessary
  • Validate compression behavior in production with realistic payload sizes

Final takeaway

Negotiation and compression are protocol-native optimizations. They are simple in concept but high impact in performance and user experience.

In Part 9, we cover connection persistence and keep-alive behavior.