This article explains data compression techniques in Nginx, including methods, supported formats, and how to enable and verify compression.
Imagine you’re packing for a week-long trip to Hawaii. If you just stuff your clothes into your suitcase without folding, you’ll struggle to close it. But if you fold them neatly and tightly, they take up far less space—and you can fit more.
Compression is the same idea applied to data: shrink files so they consume less “space” when transferred. In waste management, garbage is compacted into small cubes to optimize storage:
On the web, the server encodes (compresses) a file before sending it. Your browser then decompresses (unpacks) it and renders the original content:
Without compression, every page load requires downloading the full HTML, CSS, JavaScript, images, and more—slowing performance, especially on mobile devices or capped data plans:
By compressing resources, you reduce transfer size, speed up page loads, and enhance the user experience.
GZIP is the most ubiquitous compression format, dating back to the 1990s. Files use the .gz extension, and a CLI tool is available on most Linux/Unix systems.
Brotli often achieves higher compression ratios than gzip. Nginx Plus includes Brotli by default, while open-source Nginx requires installing a module.