How to: Speed up your WordPress site with gzip compression

Enabling gzip compression on your site will dramatically reduce the amount of data sent from your server to the visitors browsers, thus increasing the page-load speed.

The top 3 benefits are:

  • A better user-experience: no one likes to wait 10 seconds for each page to load
  • SEO bonus: search engines too prefer sites that load faster
  • Reduced server load: your server will no longer have to process large requests

How to enable gzip with WordPress?

A few plugins include gzip activation, but my preferred and surefire method is to add a few lines directly to your .htaccess file.

Please, DO KEEP A BACKUP of your .htaccess file before you mess with it!

If you are used to get your hands dirty and manipulate files via FTP, you know how to proceed.
If you would rather stay within your WordPress dashboard, then this free plugin will let you simply edit your .htaccess file through wp-admin: WP Htaccess Editor

A typical WordPress .htaccess file should look like this:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

 

To enable gzip compression, simply add the following at the end of the file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png

 

And that’s it!

You can test the result directly with your browser developer’s tool (inspector), or by using some online tools such as: HTTP Compression Test. Just enter your site’s URL, and it will tell you if it is actually gzipped, and if it is, you will see the impressive compression ratio.

Size reduced by 70,53% with gzip!
Size reduced by 70,53% with gzip!

If you want to know more about gzip compression, how it works and why it’s great, then you will enjoy reading this nicely explained article on betterexplained.com: How To Optimize Your Site With GZIP Compression

And if you are serious about making your site faster, consider moving to a high performance premium WordPress hosting such as WP Engine. They offer lightning fast servers specifically optimized for WordPress to make your site fly! Check them out and optimize your site speed and increase conversions with Page Performance from WP Engine.



4 Responses to How to: Speed up your WordPress site with gzip compression

    • This option was actually available in the Settings section up to WordPress 2.5, it was then removed because it relies on a php implementation, which is far less effective, and not recommended.

      Apache/Nginx handle it far more efficiently, thus why using .htaccess to enable mod_deflate or mod_gzip is far more effective and the most recommended way to go about this.


PayPal Verified
Secured by PayPal
Secure Credit Card payments powered by Stripe
SiteLock