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? 6.1.3 "))
{
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: