How to ensure the execution sequence of JavaScript _ javascript skills

Source: Internet
Author: User
At the end of my article "how to use the same HTML clip-continued on multiple pages", I mentioned the features of JavaScript sequential execution. Although modern browsers can download JavaScript in parallel (Some browsers), their execution is still carried out in the order of introduction considering the JavaScript dependency. 1. Introduction
At the end of my article "how to use the same HTML clip-continued on multiple pages", I mentioned the features of JavaScript sequential execution. Although modern browsers can download JavaScript in parallel (Some browsers), their execution is still carried out in the order of introduction considering the JavaScript dependency.
To better test this process, I wrote a simple HTTP handler page service. ashx, which can accept two parameters:
1. file: the server path of the file to be returned.
2. delay: return the HTTP request after a certain delay (in milliseconds ).
A typical page, such as./service. ashx? File = js/jquery-ui.js & delay = 2000, indicating a 2 second delay before returning the js/jquery-ui.js file on the server.
The key code of service. ashx is as follows:

The Code is as follows:


Public void ProcessRequest (HttpContext context)
{
Int delay = 0;
If (! String. IsNullOrEmpty (context. Request ["delay"])
{
Delay = Convert. ToInt32 (context. Request ["delay"]);
}
If (delay> 0)
{
System. Threading. Thread. Sleep (1000 );
}
String filePath = context. Request ["file"]. ToString ();
String fileContent = String. Empty;
Using (StreamReader sr = new StreamReader (context. Server. MapPath (filePath )))
{
FileContent = sr. ReadToEnd ();
}
If (filePath. EndsWith (". js? 1.1.15 "))
{
Context. Response. ContentType = "application/x-javascript ";
}
Else
{
Context. Response. ContentType = "text/plain ";
}
Context. Response. Write (fileContent );
}


2. Directly import javascript(test1.htm) through the scripttag)
First, we will analyzeAdd JavaScript to the tag sequentially. The source code of the test1.htm page is as follows:

The Code is as follows:





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.