This might be more a general Varnish question than a Drupal one, so apologies if I should be asking this elsewhere.
Our site serves up different versions of pages based on country location. We look up country via IP address, set a cookie and if it the country is (say) USA, show prices based on dollars, if it's not USA show pricing in Euros [simplified example].
Currently there's some fairly lightweight code then at the start of every page which is "if cookie is not set, then work out country from ip and set cookie".
I understand in Varnish that I can hash the response based on this cookie, so can store two versions of each page and serve the appropriate one based on the cookie, which seems perfect.
But how can I set the cookie for anonymous users? Doing it via javascript doesn't really work as then the first page hit would be incorrect, although subsequent pages would be fine assuming the code runs. Is it possible to run a PHP function before Varnish serves up the correct page? Use VCL to hit a page that sets the cookie if it doesn't exist?
Comments
Comment #1
apemantus commentedMy current planned workaround by the is to try and come up with a VCL/code that is of the form:
if page is the home page or cookie is set then pass through to Varnish (homepage has no country specific content)
on home page set [long lived] cookie by a javascript call back
if page is not homepage and no cookie set, do not serve via varnish
on these pages set [long lived] cookie
This means that if anybody visits the site via any other page than the homepage then the first page they see will be uncached (and slow), but subsequent pages should be served from Varnish.
This seems non-ideal (having people's first impression of the site be a slow page) bnut am struggling to think of a better way of doing it? Maybe setting the cookie using hook_boot() in a module with a really low weight and then immediately reloading the page?
Comment #2
cmlaraLate Post I know but I really hate seeing open unanswered questions.
Possibly do VCL if request does not have Country cookie work out the country in the VCL and then set the cookie before the request is made to the cahce.
Ip subet ranges to countries changes pretty infrequently just refresh every so often.
That would ensure you have a cache response rather then a lookup.
-- Submitted from my Phone. Please excuse any errors
Comment #3
cmlaraNo change in 30 days.
Closing out.