Overview
Despite the proliferation of high-speed Internet, bandwidth usage is still a concern for web services and end users. For large web services, having to deliver hundreds or even thousands of large files can have a big impact on spend and performance.
Compression directs this issue by reducing the file size of the content before it leaves the server. Gzip, the most popular compression method, is used by web servers and browsers to seamlessly compress and decompress content as it’s transmitted over the Internet. Used mostly on code and text files, gzip can reduce the size of JavaScript, CSS, and HTML files by up to 90%.
How Gzip Works
- When a server receives a request for a web page, the server checks the header of the request to determine if the browser supports gzip
- If so, the server generates the markup for the page before applying gzip
- Gzip converts the markup into a compressed data stream which is then delivered to the end user
- When the end user receives the compressed stream, their browser decompress it
How Compression Levels Affect Resource Usage
Gzip compression is a CPU-dependent process that has different compression levels. Higher compression levels result in smaller files but are more CPU-intensive. Developers can choose how much to compress – as well as what to compress – based on the needs of the site or application they are responsible for. At StackPath we give developers the option to compress files on a level from 1 to 6 from the control panel.
Example of Gzip
A 2009 study shows the drastic impact compression can have on some of the world’s top websites. For Facebook, enabling compression reduced page load time by an average of 9.4 seconds, or 414%. A savings of 350 KB may not seem like much in today’s data driven world, but when aggregated across all of Facebook’s users it makes for a substantial improvement.
A post by Google shows an average compression ratio of 77% for some of the most popular JavaScript libraries and CSS frameworks. While Google itself enjoys a modest 10.3 KB (or 44%) savings from compressing its homepage, some CSS frameworks experience savings of up to 88%. Combined with minification and other data reduction techniques, compression can drastically reduce the size of some of the web’s most widely used libraries.
Conclusion
Over the past 10 years, the average web page has grown in size by almost 1.2 MB. As our demand for information increases, techniques for quickly and efficiently delivering large amounts of data are becoming more relevant. When a 100ms increase in page load time can reduce your sales by 1%, it’s vital to make web services as efficient as possible. Gzip compression can add a profitable speed boost to any web service.