Why Vary User-Agent added as default?

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,354
I run cb 2.0 and directadmin/custombuild seem to add these headers to apache so they are added to all sites running php:

Code:
Vary: Accept-Encoding,User-Agent

But why is "User-Agent" added here? Vary: User-Agent can cause cache inefficiency.

Have anybody removed it so the php sites server only this in the header instead?:

Code:
Vary: Accept-Encoding

Question is if I should remove "User-Agent" from vary on a global scale in shared hosting servers? If not, is it possible to remove "User-Agent" from vary header by using .htaccess for each user that don't want it?

Heres the documentation: http://httpd.apache.org/docs/2.4/mod/mod_deflate.html#proxies
 
If a server sends the Vary: User-Agent header, intermediate caches will store a separate cache entry for each User-Agent they see (every OS + browser combination.

I guess you may try to remove Vary header completely and re-add it again without "User-Agent".
 
I have not done any custom changes to add vary user-agent, it is default from custombuild 2.0 setup when using apache, mod_ruid2 and mod_php setup.

However it is not clear to me what is best, with or without user-agent. Google recommend vary user-agent: https://developers.google.com/webmasters/smartphone-sites/details

The Vary HTTP header has two important and useful implications:

1: It signals to caching servers used in ISPs and elsewhere that they should consider the user agent when deciding whether to serve the page from cache or not. Without the Vary HTTP header, a cache may mistakenly serve mobile users the cache of the desktop HTML page or vice versa.

2: It helps Googlebot discover your mobile-optimized content faster, as a valid Vary HTTP header is one of the signals we may use to crawl URLs that serve mobile-optimized content.

Here is a good read about it, also make sure you read the discussion in the replies: http://www.rimmkaufman.com/blog/vary-user-agent/30112012/

For now, I have decided to keep the global setting with vary user-agent on my shared hosting servers. But it is not so very clear what is best on a shared hosting server.
 
Warning: I'm not a PHP programmer :)

That said, from time to time I may be looking at a site with one browser and need to look at it again through another browser, to see differences. Those differences may not show up properly if the same caching is presented.

For example, if I'm logged into a Wordpress site as one user and need to log in as another user from another browser.

Isn't that why I'd want that the site use Vary user-Agent[/i[?

Or am I misunderstanding something completely?

Thanks.

Jeff
 
Usually (at least to my understanding) if a page is generated by a server for an authorised user PHP sends no-cache HTTP-headers. So nobody see your data. And "Vary user-Agent" does not interfere here. Ditto has already posted on why "Vary user-Agent" is used. The main reason it to differentiate mobile users and desktop users.
 
Thanks for the clarification, Alex. As I wrote, I'm not a PHP programmer. I may not have a full understanding as to how these work.

Jeff
 
Back
Top