How to Fix “Specify a Vary: Accept-Encoding Header” Warning 1
Linux,  VestaCP,  Webmaster,  Wordpress Themes

How to Fix “Specify a Vary: Accept-Encoding Header” Warning

Are you seeing the “Specify a Vary: Accept-Encoding Header” warning in Pingdom, GTmetrix, or Google PageSpeed Insights on your WordPress site? This is an HTTP header and should be included on every origin server response, as it tells the browser whether or not the client can handle compressed versions of the content.

For example, let’s say you have an old browser without gzip compression and a modern browser with it. If you don’t utilize the Vary: Accept-Encoding header your web server or CDN could cache the uncompressed version and deliver that to the modern browser by mistake, which in turn hurts the performance of your WordPress site. By using the Vary: Accept-Encoding header you can ensure that your web server and or CDN delivers the appropriate version.

Depending upon the tool or software reporting it, the warning might appear in a couple different ways:

  • “Specify a Vary: Accept-Encoding Header”
  • The following publicly cacheable, compressible resources should have a “vary: accept-encoding” header

Specify a Vary: Accept-Encoding header warning in Pingdom

Specify a Vary: Accept-Encoding header warning in Pingdom

Follow the steps below on how to fix the “Specify a Vary: Accept-Encoding Header” warning.

Fix “Specify a Vary: Accept-Encoding Header” Warning

The first thing that is important to note about this warning is that you can only fix this for requests that are on your server. If you have 3rd party requests you are seeing this on, there is nothing you can do as you don’t have control over their web servers. Although feel free to share this article with them. The Vary: Accept-Encoding header is added by default on all Kinsta servers (as seen below), so if you are a Kinsta customer you won’t see ever see this warning and don’t have to worry about.

vary: accept-encoding header kinsta

Vary: Accept-Encoding header on Kinsta servers

The header applies both to your WordPress assets and your original server request. For your assets, if you are using a CDN, many already apply the Vary: Accept-Encoding by default. KeyCDN, Cloudflare, and CloudFront all utilize this. A lot of WordPress caching plugins also add this.

If you are still needing to fix this, you will need to add some code to your server.

Fix “Specify a Vary: Accept-Encoding Header” Warning in Apache

To fix this in Apache, add the following code to your .htaccess file via FTP. This file can be found on the root of your server. You can also edit your .htaccess file with the Yoast SEO plugin if your permissions are set correctly.

Important! Editing your .htaccess file could break your site if not done correctly. If you are not comfortable doing this, please check with your web host first.
<IfModule mod_headers.c>
  <FilesMatch ".(js|css|xml|gz|html)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

Fix “Specify a Vary: Accept-Encoding Header” in NGINX

To fix this in NGINX, add the following code to your config file. All NGINX configuration files are located in the /etc/nginx/ directory. The primary configuration file is /etc/nginx/nginx.conf.

gzip_vary on

Using the Vary: Accept-Encoding header can in fact help speed up your WordPress site as it will ensure you are using gzip compression. And if all goes well, and you don’t have any 3rd party requests that aren’t correctly using the header, you should see an improvement on your score with website speed test tools such as Pingdom (as seen below).

100 score accept encoding header

Fixed Specify a Vary: Accept-Encoding header warning

Nguồn

Avatar of jamesblackvn

Tui là jamesblackvn!

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Website này sử dụng Akismet để hạn chế spam. Tìm hiểu bình luận của bạn được duyệt như thế nào.