How to Specify a Vary: Accept-Encoding header in WordPress?

Why should you specify a Vary: accept-encoding header in your WordPress blog?

The Vary: Accept-Encoding header — it’s not on every server response, but it should be. When browsers make a request, they include HTTP headers for the server to decide what to send back (Is this a mobile client browsing? Will the mobile handle compressed version of content?). The fix is for the origin server to send back Vary: Accept-Encoding.

Before we begin, I have already solved several issues regarding page speed of WordPress blog. Here are some articles to increase your blog page speed:

  1. How to: Remove Query String URL From Static Resources in WordPress?
  2. How to: Enable HTTP Keep-Alive in WordPress?
  3. Top 3 Methods to Enable Gzip Compression in WordPress
  4. How to: Add Leverage Browser Caching in WordPress via .htaccess?
  5. How to: Add Expires Headers in WordPress using .htaccess?
  6. How to: Use CSS Sprites in WordPress Blog?
  7. Ultimate Guide to W3 Total Cache
  8. WP Super Cache: A Guide That You Really Need
  9. 10 Easy Steps to Setup CloudFlare CDN in WordPress
  10. Defer parsing of JavaScript in WordPress

Vary: Accept-Encoding

Solution

Add the following line of codes in your .htaccess file out of Begin and End WordPress section in .htaccess file:

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

If you have any kinda problem with it, please comment below. Thanks

Related  Daily WordPress Plugins Roundup – 14 August, 2013

35 Comments

  1. Sorry I don’t understand, do I put the code after or inside. For example:

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    
      
        Header append Vary: Accept-Encoding
      
    
    # END WordPress
    1. No, dear don’t put the code in the #begin and #end wordpress tags in your .htaccass because WordPress automatically generates this section and any time you make modifications to something like Permalink settings, everything you’ve added between these lines will be overwritten. Instead put the code outside these tags…

  2. It seems that is what I was looking for but still do not know what good is having a website quick, Do visitors can gain more through google or bing?

    By the time I placed the code outside # begind and # End of wordpress. Let’s see what happens.

  3. The code works great. Thanks. I am using a WordPress Blog and I put code tag you provided in my .htaccess file.

    Thanks again

  4. Hi Muhammad

    I tried that with my blog but it does not work.
    I use WP super cache …
    My gtmetrix and pingdom performance is good but the worst result seems to be this encoding header problem and I do not know how to sort it out

    Thanks in advance

  5. I must be doing somthing wrong. It is not working for me.
    This is what I have

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Header append Vary: Accept-Encoding

    1. Yes you are doing wrong… There should be only one code of begin to end wordpress like this:


      # BEGIN WordPress

      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      # END WordPress

  6. Once you make this change in the .htaccess file does it take a little while to take effect or is it instant? Pingdom is still complaining about it.

  7. Once you make this change in the .htaccess file does it take a little while to take effect or is it instant? Pingdom is still complaining about it. I hope I did it right.

Leave a Reply

Your email address will not be published. Required fields are marked *