Prompt
How do I personalize content based on user location at the edge?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To personalize content based on user location at the edge, you typically use the user’s request metadata (especially IP-derived geo headers) in an edge worker, then choose content, variants, or routing logic before the origin is hit.
Common approach
1) Detect location at the edge
Most CDNs/edge platforms provide geo signals such as:
countryregion/statecitytimezone- sometimes latitude/longitude or postal code
Examples:
- Cloudflare:
request.cf.country,request.cf.region, etc. - Fastly/other CDNs: geo headers like
Fastly-Geo-Country, custom injected headers - Vercel/Netlify/Akamai: platform-specific geo/request metadata
2) Use that data to select content
Typical patterns:
- Redirect to a localized page
e.g./us,/ca,/de - Rewrite internally while keeping the URL stable
- Inject dynamic content
e.g. local store, currency, language, legal copy - Choose from cached variants
e.g. serve one of several pre-rendered versions
3) Keep cache behavior safe
If the content varies by location, you need to avoid serving the wrong version from cache. Common strategies:
- Cache by a coarse geo key like country, not city
- Use separate cache keys per locale/region
- Store a small number of variants, e.g.
US,EU,ROW - Avoid caching highly personalized data unless necessary
4) Add fallback logic
Geo data is imperfect. Have defaults for:
- missing location
- VPN/proxy users
- mobile carrier NAT
- unsupported regions
Usually:
- Use user preference/cookie first
- Then geo
- Then browser language
- Then default
Example edge worker logic
export default {
async fetch(request, env, ctx) {
const country = request.cf?.country || "US";
let variant = "default";
if (country === "US") variant = "us";
else if (country === "CA") variant = "ca";
else if (["DE", "AT", "CH"].includes(country)) variant = "de-ch";
const url = new URL(request.url);
url.pathname = `/${variant}${url.pathname}`;
return fetch(url.toString(), request);
}
}
Better personalization ideas
Instead of hard-redirecting, you can personalize:
- currency
- shipping availability
- nearest store
- local promotions
- language defaults
- compliance notices
Important considerations
- Privacy: location is sensitive; be transparent and follow local rules
- Accuracy: IP-based location can be wrong
- SEO: redirects can affect indexing; use hreflang and canonical tags if needed
- Performance: avoid expensive origin calls; do lightweight edge logic
Recommended best practice
Use coarse location personalization at the edge:
- country or region level
- server-side rendering or edge rewriting
- cache variants by location bucket
- let users override with preferences
If you want, I can show you a working example for a specific platform like Cloudflare Workers, Fastly, Vercel Edge, or Akamai.