JavaScript performance optimization skills

Source: Internet
Author: User
Load and run the extension script & lt; scripttype


Loading and running
  • Extension script

       
        
    The script js file is downloaded only when the dom is loaded.
       

  • Dynamic script Element

    Var script = document. createElement ("script"); script. type = "text/javascript"; script. src = "file1.js"; document. getElementsByTagName_r ("head") [0]. appendChild (script) does not block the processing process of other pages no matter where the download starts.

  • XHR Script Injection

    Var xhr = newXMLHttpRequest (); xhr. open ("get", "file1.js", true); xhr. onreadystatechange = function () {if (xhr. readyState = 4) {if (xhr. status >=200 & xhr. status <300 | xhr. status = 304) {var script = document. createElement ("script"); script. type = "text/javascript"; script. text = xhr. responseText; document. body. appendChild (script) ;}}; xhr. send (null) generates inline js Code on the html page. It is not executed immediately after being downloaded, so it can control its execution status.

  • Recommended Practices

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.