With this 1-Hour WordPress tutorial, we will once again be working in the .htaccess file. So get comfortable, we’ll be adding a few lines of code to enable gzip compression in your WordPress install. While this isn’t specific to WordPress, it does help you by allowing you to reduce the number of plugins on your WordPress website by one.
What happens when you enable gzip compression?
When you enable gzip compression, you’re reducing the size of files sent from your server to increase the speed to which they transfer to the browser. In English? This means your website downloads faster because the files used for it are smaller.
How to enable gzip compression
This walk-through is for Apache servers. If your server is IIS, visit the Microsoft TechNet document to enable compression.
Step 1: Check your sites performance
You can’t know how much you’ve improved your site without creating a starting benchmark. I recommend testing with GTMetrix.
I’ll be making changes for this tutorial on a test website. Here is the GTMetrix score, pre-edit:
Step 2: Open your .htaccess file
Add the following code to the bottom of the file:
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
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
AddType text/css .css
And that’s it!
Here is the score for my test website, after adding the code to enable gzip compression:
Just look at that improvement! Just a few quick changes in the .htaccess file made the Page Speed grade jump from a D to a B and reduced the page size almost in half. Not to shabby for a mere 15 minutes worth of work… most of which was just logging into the server!
So, did this work for you? What improvements did you see in your Page Speed and YSlow grades?