Use js to count the scripts for the time the user needs to download the web page

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.