How does Gzip work? In short: Gzip compresses a file before it's sent to the browser of the user (ie. a visitor on your website) and their browser then decompresses the Gzipped file automatically to load the full original file in their browser.
You can actually use two different Apache mods to enable HTTP Gzip compression: mod_gzip and mod_deflate. Mod_gzip enables Gzip compression and mod_deflate makes it possible to compress the output from your server before it is being sent to your visitor (which is the same thing). So should you be compressing your resources with Gzip or deflate? In the end it doesn't matter much, both modules will provide you with the same maximum Gzip compression possible. But, as a general rule it is recommended to use mod_deflate since it’s more widely supported compared to mod_gzip. Mod_deflate is also better documented and easier to configure. If mod_deflate doesn't work on your server you can still use mod_gzip. Not every host has these modules enabled on their servers, so make sure you ask your host about this when the below .htaccess scripts do not work. Add one of the below scripts to your .htaccess file (which can be found or should be placed in the root folder of your website (usually /var/www/html/)):
You can download the above script in a .htaccess file here.
Download the above script in a .htaccess file here.
When you just want to compress certain components or a certain file type with Gzip, make sure that you include this file type to one of the above lists. And again, make sure at least one of the mods is enabled on the server. If you don't want to compress a certain file type, just remove this file type from the code.
Please follow the below steps to enable Gzip in Nginx:
Open the Nginx configuration file for your website using your preferred text editor. The configuration file is usually located in /etc/nginx/nginx.conf or /etc/nginx/sites-available/your-site.conf, depending on your setup.
sudo service nginx restart
That's it! Now test your website using our gzip test to see if what you changed is working!
When your website is hosted on a Windows server, you can enable compression for both static and dynamic files. It’s fairly easy to set this up in the IIS manager:
When you can't get it working visit this page to learn how else you can set it up in IIS 10.
There are multiple plugins available to enable gzip compression in WordPress. They are easy to find in the "Add a plugin" section of the WordPress admin, some work better than others. However, please note that it is recommended to always use one of the above server side methods to enable Gzip.
The note: Brotli was initially developed for use with the Google Chrome web browser, but has since been adopted by pretty much all other web browsers and web servers. Unfortunately, not all yet. This is why, at this moment, it is still better to use Gzip as the main compression method for all browsers. You can however, use a "switch strategy" where you can switch between Gzip and Brotli depending on which browser the user is using. More on this very soon!
We can help with that! We have professionally optimized the speed of thousands of websites. Because of this we know how to get the best results quickly while keeping our prices low. Get an instant price quote for our services now.