Fewer Bytes, More Work
Compression shrinks data before it crosses the network, so fewer bytes travel. It trades extra processor work at both ends for reduced transfer size and time, which often pays off on slow or distant links.
Where It Applies
Compression appears at several layers.
- Payload compression shrinks response bodies such as text and scripts before sending.
- Header compression removes repeated request fields that would otherwise repeat on every request.
- Streaming compression lets a sender compress as it produces data rather than buffering it all.
Already compressed media such as images and video gains little, so re compressing it wastes work.
A Security Caution
Mixing compression with secrets can leak data. If an attacker can influence part of a compressed and encrypted message, the change in compressed size can reveal a secret, an attack class behind several named exploits. The fix is to avoid compressing sensitive fields together with attacker controlled input.
Key idea
Compression trades processor time for fewer bytes across payloads and headers, helps most on slow links and uncompressed data, and must avoid mixing secrets with attacker controlled input to prevent size based leaks.