This article mainly introduces how to allow concurrent download of JavaScript and other resources. The main purpose of concurrent download of JavaScript is to solve the problem that JS loading will impede page rendering, if you need JavaScript in IE6/7, you can see that JavaScript will hinder page rendering in two ways:
The webpage resources under the script tag stop requests and downloads before the script is loaded.
The html element under the script tag stops rendering before the script is loaded.
The script tag in ie6/7 firefox2/3 Safari3 Chrome1 and opera will impede download:
Although scripts in ie8, safari4, and chrome2 can be concurrently executed, downloading other resources is still blocked:
There are six methods for parallel download of scripts and other resources:
1. XHR eval-download the script through XHR (XMLHttpRequest object), and then use the eval method to execute the XHR responseText
2. XHR Injection-download the script through XHR, create a script tag, and insert it into the document (body or head tag ), set the text attribute of the script tag to the value of responseText of XHR.
3. XHR in Iframe-put the script tag in an iframe and download it through iframe
4. Script DOM Element-create a script tag and point its src attribute to your Script address
5. Script Defer-Add the defer attribute of the script tag. This attribute is valid only in ie, but firefox3.1 also supports this attribute.
6. Use the document. write method to write data to the page