Enable Specify A Vary: Accept-Encoding Header To Speed Up WordPress
In this article we will be learning How You can fix Specify A Vary: Accept-Encoding Header warning in gtmetrix and pingdom tool on Your WordPress website so that you can increase your website performance grade . We will fix this warning for htacess , ngnix , php WordPress and iis Servers .You will face this error or warning in like Pingdom , GTmetrix. or webpagetest
What is Vary Header ?
Vary Header is a very important HTTP header of our website. It ensures that the right content (compressed or uncompressed) should be delivered to a particular browser when requested.
Concept elaboration in detail
Now days we have two kinds of browser. Modern Browser which accepts gzip compression and second one is the old browser which doesn’t understand gzip compression. Let’s say first visitor is using modern browser and you haven’t enabled Vary: Accept-Encoding Header then your server will deliver the cached version of gzip compressed content. And now let say second visitor is using old browser and your cache server have gzip compressed content and it will deliver to second visitor. Since the old browser doesn’t understand gzip compression so the delivered content will be unreadable for your visitor. This case becomes more complicated when proxy server comes in between the client browser and cached server. So in this case vary header will only deliver the right content.
How to Fix “Specify a Vary: Accept-Encoding Header” warning using htaccess (Apache server)
You need to paste below code in .htacess file
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
How to Fix “Specify a Vary: Accept-Encoding Header” Warning NGINX server
You need to add it to your NGINX server config file Path followed will /etc/nginx/nginx.conf
gzip_vary on
Vary: Accept-Encoding Header IIS
You need to edit web.config file
<?xml version="1.0" encoding="UTF-8"?>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary"></remove>
<add name="Vary" value="Accept-Encoding"></add>
</customHeaders>
</httpProtocol>
</system.webServer>
Best WordPress plugins to fix Specify a Vary: Accept-Encoding Header are as follows
You need to install this plugin and activate it. Once you are done the above mentioned code will get added to your .htacess file .
Download