Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Varnish cache different for Mobile / PC/ Tablet
## ## Not complete default.vcl code
# Routine to try and identify device
sub identify_device {
# Default to thinking it's desktop
set req.http.X-UA-Device = "desktop";
if (req.http.User-Agent ~ "iPad" ) {
# It says its a iPad - so let's give them the tablet-site
set req.http.X-UA-Device = "tablet";
}
else if (req.http.User-Agent ~ "iP(hone|od)" || req.http.User-Agent ~ "Android" || req.http.User-Agent ~ "Windows Phone" || req.http.User-Agent ~ "[ (]BlackBerry;") {
# It says its a iPhone, iPod, Android or BlackBerry - so let's give them the touch-site..
set req.http.X-UA-Device = "smartphone";
}
else if (req.http.User-Agent ~ "Kindle" || req.http.User-Agent ~ "^nook browser") {
set req.http.X-UA-Device = "ereader";
}
else if (req.http.User-Agent ~ "SymbianOS" || req.http.User-Agent ~ "^BlackBerry" || req.http.User-Agent ~ "^SonyEricsson" || req.http.User-Agent ~ "^Nokia" || req.http.User-Agent ~ "^SAMSUNG" || req.http.User-Agent ~ "^LG" || req.http.User-Agent ~ "IEMobile" || req.http.User-Agent ~ "Windows CE") {
# Some other sort of mobile
set req.http.X-UA-Device = "mobile-other";
}
}
sub vcl_recv {
call identify_device;
}
sub vcl_hash {
hash_data(req.url);
if (req.http.X-UA-Device){
# Add device info with uniqueID cache
hash_data(req.http.X-UA-Device);
}
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (lookup);
}
@fatihtoprak
Copy link

fatihtoprak commented Jul 7, 2021

its says syntax error

@marcofbb
Copy link
Author

marcofbb commented Jul 7, 2021

@fatihtoprak

its says syntax error

Ready fixed

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment