Everyone who has an online presence wants to have a fast loading speed of the webpage or the website. The speed is checked by using tools such as GTmetrix, Pingdom, or Google PageSpeed Insights. These tools summarize your page performance and provide warnings and recommendations for a fast running page. One such warning that appears is "Specify a vary accept-encoding header". This article deals with the ways in which the warning can be fixed.
Let us first understand the meaning of the "Specify a vary accept-encoding header".
Accept-encoding header is an HTTP header that is crucial to be included on every origin server response. It’s main function is to inform the browser that weather a client can handle the compressed version of the website.
For instance, let's assume you have an older browser without gzip compression and a modern browser with it. If you are not using Vary: Accept-Encoding header your web-server or CDN could cache the uncompressed version and can send it to the modern browser mistakenly. This will in turn affect the performance of your website. Using Vary: Accept-Encoding makes sure that the appropriate version is delivered by your server or CDN.
Fix "Specify a Vary: Accept-Encoding Header" Warning in Apache
Add the below code to your .htaccess file.
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
You may also like to read:- How to Enable GZIP compression its Importance, and Benefits
Fix "Specify a Vary: Accept-Encoding Header" Warning in NGINX
Add the code to the config. File. The files are located in /etc/nginx/ directory and the primary configuration file is /etc/nginx/nginx.conf.
gzip_vary on
Conclusion
This article illustrated some ways in which you can specify a vary: accept-encoding, which will eventually help speed up your website because it ensures you are using gzip compression.
Hope you enjoyed this article.