Extend Fastly to vary its caching per user-agent: BingBot and GoogleBot and the rest.
Hi,
We are trying to implement a new VCL to vary caching based on certain bots. Please see recv VCL as implemented below.
if ( req.http.User-Agent ~ "(?i)(ads|Google|bing|msn|yandex|baidu|ro|career|seznam|)bot" )
{
set req.http.X-UA-Device = "Googlebot";
set req.http.Vary = " X-UA-Device";
return(lookup);
}
Do you see any issues that could bring a performance impact on the above mentioned?
-
Hi Gulshan,
I don't see any issues in Varying on a custom header as you do in the code.
You just need to set the Vary header in the responses. Here is an example:vcl_recv
if ( req.http.User-Agent ~ "(?i)PATTERN1" ) {
set req.http.X-UA-Device = "Bot";
} else if ( req.http.User-Agent ~ "(?i)PATTERN2" ) {
set req.http.X-UA-Device = "Mobile";
} else {
set req.http.X-UA-Device = "Desktop";
}vcl_fetch
if (beresp.http.Vary) {
set beresp.http.Vary = beresp.http.Vary "X-UA-Device";
} else {
set beresp.http.Vary = "X-UA-Device";
}
Please sign in to leave a comment.
Comments
2 comments