Region detection in pages website

What's the best way to detect the region of a user? I am currently intercepting the requests of our Pages website using Cloudflare workers, and adding a cookie to add country/region data from the geolocation data available inside Cloudflare workers.

Is it a good idea to get the region data in this way?? I am already facing two issues:

  1. Modifying the response adds around 100-200ms of delay to the page load. And Cloudflare also generates a new Etag for every request since the response is being modified, so it also invalidates the browser cache.
  2. And also I couldn't make the worker intercept the requests for the preview websites created from non-production branches. What do I have to use as the route pattern??
Was this page helpful?