Last active
December 28, 2021 12:24
-
-
Save marcofbb/99b7c1fdc14d2a262844a9d20d466ff0 to your computer and use it in GitHub Desktop.
Varnish cache different for Mobile / PC/ Tablet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ## 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its says syntax error