Menu

Post image 1
Post image 2
1 / 2
0

Geo-Redirect Users at the Edge with Vercel + ApogeoAPI in 10 Lines

DEV Community·ApogeoAPI·29 days ago
#hxIYPcTQ
Reading 0:00
15s threshold

If you serve users in multiple regions, geo-routing is one of those features that sounds complicated but is actually trivial on Vercel. Vercel's Edge Network already knows which datacenter is closest to the visitor — what's missing is enriching that with country / city / currency data so you can do something useful with it. This tutorial: 10 lines of middleware that intercept every request, look up the visitor's country, and rewrite the URL to a locale-specific path. No client-side flicker, no double network round-trip. Why edge instead of client-side? The naive approach is detecting country in the browser via fetch() to your geo API after the page loads. Two problems: Layout shift. The page renders in English, then 200ms later swaps to Spanish. Users notice. Wasted server work. If the rendered page is per-locale, you're rendering the wrong one first. Edge middleware runs before the page renders, so the response that hits the browser is already correct.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More