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:
- How to: Remove Query String URL From Static Resources in WordPress?
- How to: Enable HTTP Keep-Alive in WordPress?
- Top 3 Methods to Enable Gzip Compression in WordPress
- How to: Add Leverage Browser Caching in WordPress via .htaccess?
- How to: Add Expires Headers in WordPress using .htaccess?
- How to: Use CSS Sprites in WordPress Blog?
- Ultimate Guide to W3 Total Cache
- WP Super Cache: A Guide That You Really Need
- 10 Easy Steps to Setup CloudFlare CDN in WordPress
- 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
Sorry I don’t understand, do I put the code after or inside. For example:
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…
Thank you very much, I really appreciate!
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.
Oh! Yeah @Roberto. I hope you will surely see an outstanding performance for your website and your visitors will be happy too…
Thanks for your nice explanation on this.. I had faced problem with this HTaccess editiong.
Hi @Lionel, I’m glad that you troubleshoot the problem. Keep visiting for more unique stuff.
Thanks for that
My sites load times have fallen from 2.oo sec to .508 ms
Very pleased
Thanks
Hi @Greg, your welcome. By the way, I was my pleasure so…
im geting 98 and 99 A,A on gtmetrix score but on google page speed am getting 72 y is that dfference
The code works great. Thanks. I am using a WordPress Blog and I put code tag you provided in my .htaccess file.
Thanks again
Works 🙂
Pingdom Specify a Vary: Accept-Encoding header tests just went from 54 to 89
Yeah, it did work… @Dean.
It works thanks
Yeah, it does. @Shailendra.
Great.. very effective it works on my site and gmetrix point now A
Thanks for commenting your opinions.
Keep visiting us.
Kind regards,
Muhammad Haroon
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
You should consult this with your web host because it is server side problem. And currently your server is not handling the .htaccess file seriously. 🙁
OMG!!!! It worked! WOWWOWOW! Went from a 24 to a 95! Thank you!!!!
It helped me much when I was in a problem. Thanks.
GREAT!!! quick and easy fix and improved my page load from 24 sec to 8 sec. WOOOW !!!
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
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
SO, what if you use nginx and not Apache for hosting your WordPress?
Thanks so much, it worked. God bless.
So should it look like this
# BEGIN WordPress
Header append Vary: Accept-Encoding
# END WordPress
Don’t your site will be broken. Don’t remove WordPress begin and end comments to add your custom codes in htaccess. Add your codes below these comments.
Could you show what needs to be between the# BEGIN and #END please?
Check my previous reply.
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.
Try other page speed testing tools.
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.
The code is not working for me. the error keep showing on pingdom after adding it to my site..
Contact your web host to enable support for Encoding headers.