How to enable concurrent download of JavaScript and Other Resources _ javascript skills

Source: Internet
Author: User
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

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.