When you try to load a web page, there are a few steps that have to take place:
- Your browser sends a request to the site’s server
- The server finds the page and sends it to your browser
- Your browser downloads the page and displays it on your screen
Since web users are impatient, reducing the time each step takes will help you realize major benefits in your user experience and SEO performance.
Fortunately, there’s a way you can configure files on your server that can reduce their sizes by up to 90%, which means it takes less time for a browser to start showing the page to a user.
This is accomplished by enabling compression on your server and sending zipped versions of files to users’ browsers. These zipped files are much smaller in size than the normal version, so transfer takes much, much less time.
The users’ browsers are able to download, unpack and display these files quickly.
In this guide, you'll learn...
- What is Compression
- Why Does Compression Matter in SEO?
- How to Enable Compression
- Testing Your Compression
What is Compression?
Compression is the process by which files on a server are encoded to take up less space, making them easier and faster to send. On a technical level, compression works by scanning a file, finding repetitive data and replacing duplicates with a unique identifier that takes up less space than the original data. When a file is uncompressed, those unique identifiers are replaced with the original data.
There are lots of different formats for compression files, but not all browsers will necessarily support a given format. Except for one.
All modern browsers are able to automatically receive and handle files compressed using the gzip format. So you don’t have to worry about any users being unable to properly load any files.
Why Does Compression Matter in SEO?
Compression matters for SEO because speed matters in SEO. Web users don’t like waiting for pages to load (as we’ve discussed), so Google isn’t really interested in recommending slow pages to their users.
As such, how quickly Google is able to connect to your site and access content and information to a user has a direct impact on rankings.
How to Enable Compression
How you enable compression on your server depends on your server. Here, we’ll go over the most common ways of enabling compression for various servers.
Enabling compression via .htaccess
For most people, enabling compression means adding code to their
.htaccess on their server. If you’ve got WordPress, you can use a plugin to edit this file. Otherwise, you can use your file manager for this.
Add this code to your
.htaccess file to enable GZIP compression:
Then save your file and refresh your page.
Enabling compression on Apache servers
The above method used work with Apache webservers. However, new Apache servers now use a method called
To use it, delete the code you added above and replace it with this:
The benefit of using deflate over gzip is that deflate works automatically with Apache servers while gzip has to be installed first. However, gzip does compress files more than deflate, so if you have a lot of images or larger files, it’s probably worth your time.
Enabling compression on NGINX servers
To enable gzip compression on an NGINX server, open the main Nginx configuration file in your preferred text editor. Find the
gzip settings section in the file. This section looks like this:
By default, gzip compression is enabled (you can see this with the
gzip on directive). However, you’ll see that lots of settings have been commented out by putting the
# at the start of the line. To optimize your gzip compression, you’ll want to uncomment these settings and then add some more.
To this code, we’ll add
gzip_min_length 256;line. This tells Nginx not to compress any files smaller than 256 bytes. Files this small won’t see much benefit from gzip.
gzip_typesline at the bottom, add additional file types
application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon. This will allow compression for web fonts, icons and SVG images.
After you’re all said and done, your gzip settings should look like this:
Now save and close your file. Enable all your changes by restarting Nginx.
Testing Your Compression
Once you’ve added whichever bit of code applies to your server, you should test it. Running a WooRank Review of your site will test whether or not your files are being compressed.
You can also use Google’s PageSpeed Insights tool to test for uncompressed files.