[英]Does Varnish-devicedetect cookie based User-agent override require vary: cookie for correct browser caching?
varnish-devicedetect lets me return different responses based on User-agent: varnish-devicedetect让我根据用户代理返回不同的响应:
...
elsif (req.http.User-Agent ~ "(?i)ipad") { set req.http.X-UA-Device = "tablet-ipad"; }
elsif (req.http.User-Agent ~ "(?i)ip(hone|od)") { set req.http.X-UA-Device = "mobile-iphone"; }
...
and lets users opt into a different device experience by setting a cookie: 并允许用户通过设置Cookie选择不同的设备体验:
if (req.http.Cookie ~ "(?i)X-UA-Device-force") {
...
}
Do I need to add Vary: Cookie
to get correct client caching behavior? 我是否需要添加
Vary: Cookie
才能获得正确的客户端缓存行为?
For example: 例如:
Vary: User-agent
Vary: User-agent
X-UA-Device-force: pc
. X-UA-Device-force: pc
进入桌面体验。 Yes, you need to set a Vary: Cookie
header to get the correct behaviour since different cookies would retrive different output. 是的,您需要设置
Vary: Cookie
标头以获取正确的行为,因为不同的Cookie会检索不同的输出。
You'll need also to take care of the cookie on vcl_recv
setting the appropriate X-UA-Device
in order to hash items correctly in varnish. 您还需要注意在
vcl_recv
设置适当的X-UA-Device
的cookie,以便正确地对清漆中的项目进行哈希处理。
If you vary cookie, then you might as well through caching out the window since most users will have different cookies (especially so if you have any analytics on your site) so you will have a low hit rate and multiple copies of the same data in your cache. 如果您使用不同的Cookie,那么您最好还是缓存整个窗口,因为大多数用户将使用不同的Cookie(尤其是如果您的网站上有任何分析功能的话),因此您的点击率较低,并且相同数据的多个副本您的缓存。
Rather than vary cookie, do a hash on the specific cookie value like so: 而不是更改cookie,而是对特定cookie值进行哈希处理,如下所示:
if (req.http.cookie ~ "(?i)X-UA-Device-force" ) {
hash_data("deviceforce");
} else {
hash_data("nodeviceforce");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.