I’m working on a purchase page for a new product that the inventor is expecting to receive significant media coverage for (time will tell…). We’re building a simple 1-page product page using HTML, CSS and using Stripe’s (hosted) checkout pages.
We’re trying to minimise the amount of back-end logic needed as this is less able to be cached by CloudFlare.
We do however need to show the product pricing in different currencies depending whether the visitor is in the UK (GBP), Europe (EUR) or US/Rest of World (USD).
CloudFlare will pass a header (HTTP_CF_IPCOUNTRY) (when turned on) with a country code to our upstream webserver – but this wont always be available if we’re aiming to cache the entire page.
Any clever ideas?
I’m thinking an ajax call to a geo-location service perhaps?
Advertisement
Answer
It seems like you will need something dynamic to achieve this. If you can offload this to a geolocation service with javascript as you mentioned, this would probably be the best.
If you end up having to make the dynamic component yourself, I think you would have the least dynamic requests by making a page that redirects to a static page for each region based on user location. A page like this would be easy to make in Cloudflare workers and cheap ($5/month + $0.50 per million requests). You should probably give the option to users to override their region manually because of the inaccuracy of ip geolocation in general.
There is an option to make it completely static by asking the user their location from the browser and then making a javascript function to map this to a currency/region, but users will likely reject your location request en masse, and I wouldn’t consider it a truly useable option.