I’ve just set up a website on a new server, and I’d like to cache the
text/html pages to improve speed.
But the only thing I need to work around is the fact that each page has slightly different advertising on it, and it’s based on which country the visitor is from and whether they are on a mobile or not.
I’ve looked in to using Varnish and it seems like caching different pages based on country/mobile would be possible. To set it up I was thinking I could:
- Use the
CF-IPCountryheader set by Cloudflare.
- Grab the
User-Agentheader in Varnish, and use it to create a new simple header like
- Generate the page in the webserver, and add
Vary: CF-IPCountry, Mobileto allow the cache to cache different pages for different mobile devices and countries.
I think that might work in Varnish, but Cloudflare has always been easy to use and reliable, so would prefer to use Cloudflare where I can.
Does Cloudflare use the Vary header when determining what to cache? If so, is the above setup of caching based on country/mobile something that I could also achieve using the Cache Everything Page Rule in Cloudflare?