Redirecting to the closest site using Javascript
I'm sure this problem has been solved this way many times before, but I haven't seen it while idly browsing around sites about scalability and load balancing. So here it is, a Javascript solution to the closest-site problem .
For static content optimizing for latency is easy and cheap. Just put your files in a CDN such as Amazon CloudFront and you're done. Low (lower) latency all over the world. Done.
For dynamic content it's a bit harder. You can set up several data centers (sites) and
try to redirect the user to their closest site. But how do you find out what site is the closest one,
and how do you redirect the user to the right one?
There are several solutions to this, such as using anycast BGP or source-aware DNS. But they have big drawbacks.
DNS based solutions depend on the users resolver to be close to the user and that the ip2location database is correct.
BGP-based solutions depend on you having access to BGP (and the staf...