When someone enters your site, a request is sent to your server to deliver the requested file. The larger these files are, the longer it will take to load. By compressing your web pages and CSS before sending them over to the browser you will significantly reduce the loading time as the files will be smaller.
In short, gzip finds similar strings within a text file and replaces those strings temporarily, thus making the overall file size smaller. Gzip compression is really beneficial in a web environment because HTML, CSS files use a lot of repeated text and spaces. In the final result gzip can compress the size of pages and CSS by up to 60-70%.
IMPORTANT! Gzip speeds up your site, but in return it uses more CPU. Before enabling it, make sure that your CPU usage is stable.
What you’ll need
Before you begin this guide you’ll need the following:
- Access to
- cPanel access (optional)
Table of Contents
Step 1 — Enabling gzip compression
You can enable gzip on your website using either
mod_deflate. The compression with
mod_deflate is generally recommended due to a better conversion algorithm and the module itself being comptactible with a higher versions of apache. More information about the two methods can be found in this Linux Journal article.
Option 1. Editing .htaccess
Gzip compression via
mod_deflate (recommended) can be enabled by implementing the following code to your
.htaccess file (a guide on how to locate your
.htaccess file can be found here):
If your server does not support
mod_deflate you can try the
Once the changes are saved, gzip compression will be enabled.
Option 2. CMS plug-ins
WordPress users can enable gzip compression by installing plugins such as GZip Ninja Speed Compression.
With Joomla, you can gzip your website via Sytem -> Global Configuration -> Server section. You can also view our guide on Joomla performance here.
Option 3. Gzip via cPanel
If you have a cPanel license, you can enable gzip for all websites under your hosting account using Optimize Website section. A detailed guide can be found here.
Option 4. Windows-based hosting
If you are using a Windows server, you can enable HTTP compression for static and dynamic content using the command line:
appcmd set config /section:urlCompression /doDynamicCompression:True
appcmd set config /section:urlCompression /doStaticCompression:True
For more specifics, you can view the official Microsoft guide .
Step 2 — Testing Gzip Compression
Looking for a better way to host your website?
Transfer your website to the fastest web hosting platform with 24/7 dedicated support.
Here are the results BEFORE adding gzip compression:
For comparison, here are the results AFTER adding adding gzip compression:
In this short guide, we have learned how to increase the performance of a website by enabling
mod_deflate compression via .htaccess, CMS plug-ins, cPanel and Windows server.