What is Gzip Compressions?
Why is Compression Important?
Improves page speed
HTML or CSS files that have been compressed using GZIP can save anywhere between fifty to seventy percent of the file size. As a result of this, web pages take lesser time to load, rendering the page much faster for the user’s view.
GZIP compression helps save bandwidth and all modern browsers accept GZIP compressed files.
Let's imagine the web browser and the server to be two people talking to each other.
Browser: Server, can I get index.html?
Server: Hello Browser. I found index.html which is 100 kb. Let me zip it for you and send it Browser: Thanks! The zipped file is just 10 kb. I’ll unzip it and display it to the user.
While this is in a conversational tone for better understanding, what really happens is that the browser sends a header to let the server know that it accepts zip files.
The header content will look something like this - Accept-Encoding: GZIP, deflate (GZIP and deflate are compression methods) If the file has been compressed by the server, it will send a response like this - Content -Encoding: GZIP
How to Enable Gzip Compression?
GZIP compression is enabled through web server configuration including compression via Apache, Litespeed, Nginx and .htaccess web servers. It can compress all types of files. However, some file formats are compressed more effectively than others.
For instance, text files including HTML files are compressed well using GZIP compression. On the other hand, images are not compressed by GZIP as well, since they already have built-in compression.
Things To Keep In Mind?
1. Older versions of browsers may have trouble accepting compressed files. For such browsers, you may want to avoid compression.
3. Most images and videos, by virtue of their large sizes, are already compressed, so you need not spend time compressing them again.
4. While most servers automatically compress files when serving the user, some require manual effort to ensure that GZIP compression is being done. It is recommended that you audit your site to ensure that your files are being compressed to deliver optimum results to the users.
5. GZIP compression happens across HTTP and is the end user is completely unaware of the behind-the-scenes-works.