If you frequently testing the load speed of your website using test tools like Google PageSpeed, chances are you have encountered HTTP header error. Often times, this error takes the form of a warning which reads: “Specify a Vary: Accept-encoding Header” warning in Google PageSpeed or Pingdom. This error is most common on websites that run on Apache and Ngnix web server.
So, what does this error mean? Does it affect the performance of a website? If it does, to what extent? Most importantly, how can the problem be handled?
These are some of the questions we will be addressing in this post, so stick around.
In this article:
- Specify a “vary accept-encoding header error”: what does it mean?
- How does it affect the performance of my website?
- Fixing specify a vary: accept-encoding header error
Specify a “Vary Accept-Encoding Header Error”: What Does it Mean?
By standards, when an HTTP request is made from a browser, especially modern browsers, to a server, such a request must be accompanied by an HTTP request header.
The job of this header, basically, is to tell the server which type of content will be sent to the browser for caching. And by content type, we mean compressed or uncompressed versions of a website’s content.
But for this to happen, there has to be a Vary: Accept-Encoding header on your original server or CDN.
The absence of this vary header encoding triggers a warning, which if not instantly dealt with can hamper your website performance.
How Does This Affect the Performance of My Website?
Like earlier said, leaving this error unchecked can harm the loading speed of your website severely. Reason being that a poorly configured web server, more often than not, caches uncompressed files to a browser, including js files.
And an uncompressed file takes a longer time to load.
Fixing Specify a Vary: Accept-Encoding Header Error
By default, some web hosts companies and CDN networks include Vary: Accept-Encoding rules to their servers. If your hosting company is one of them, then you don’t have to worry because the error has been taken care of (and you frankly shouldn’t have seen it in the first place).
However, if it happens that your WordPress hosting company doesn’t enforce that and you are getting the error, we will show you how to fix it in this tutorial.
Before we go any further, we are assuming that your website runs on Apache or Nginx web servers. Unsure which yours run on? Reach out to your host provider
For Apache Server
For websites that run on Apache server, fixing Vary accept-encoding header warning will require making edits to the configuration file of the website, which is known as the .htaccess file.
But before making any edit, we recommend that you create a backup for your website.
The next step is to establish a connection to your website remotely via an FTP program such as FileZilla.
After establishing the connection, locate the folder containing your wp files and open it. If your site is accessed using your main domain name (www.yourdomain.com), then the folder will be puclic_html. If it is accessed with a subdomain (wpsite.yourdomain.com), you would see a folder named similar to your subdomain.
When you find the right folder, double click to open it. Within this folder, locate the .htaccess file,right-click on it and, select View/Edit..
To set vary content-encoding rule, add the following piece of code to the file.
<IfModule mod_headers.c> <FilesMatch ".(js|css|xml|gz|html)$"> Header append Vary: Accept-Encoding </FilesMatch> </IfModule>
If you noticed a code similar to the above is already there, modify the existing code to match the one above, exactly.
Save the file and close. And with that, you are done!
For Nginx Server
Similar to Apache, you will need to make edits to the root files of your webserver to solve Vary Accept-encoding Header Error.
To do so, navigate to /etc/nginx/nginx.conf directory in your Nginx web server.
Then paste the following line of code to the file.
If you are looking for ways to speed up your WordPress website, onesome of the things you can do is to enable gzip compression. You can take things further by including Vary: Accept-Encoding to header response of every HTTP request. This helps ensure your compression works properly and uncompressed files are not being cached.
In one of our previous WordPress tutorials we explained the concept of gzip compression. And in this tutorial, we showed you how to fix Vary Accept-encoding Header Error. With the knowledge you have now, you can supercharge your website’s loading.