Sometimes, we may choose servers in the South based on multiple servers and IP computing, and select servers in the north Based on servers in the south. However, we gradually find that errors often occur when using IP statistics. I used to think about how to ping the client to see which server is fast to connect, but at least the user needs to install a plug-in. now, it seems that using js can solve some problems.
<Script language = "javascript">
Function getDate ()
{
Var d = new Date ();
Var s = d. getUTCSeconds ();
Var m = d. getUTCMilliseconds ();
Return s + ":" + m;
}
Var d1 = getDate ();
Function _ onload ()
{
D2 = getDate ();
// Calculate the difference between d2 and d1 and send the result to the server using xmlhttp
Alert (d1 + "----" + d2 );
}
Window. onload = _ onload;
</Script>
The download speed of each server and client is calculated based on the difference between d2 and d1. The download speed is included in the cookie and then compared. Select a fast one. in addition, the cookie will be updated once in a certain period of time to make a positive response.