Performance optimizations for "Digest" JavaScript: Loading and executing

Source: Internet
Author: User

1, the browser encountered JS code will pause the page download and rendering, who know the JS code will not give the HTML to rape (change);

2. Delay Script loading: Defer property

<HTML><Head>    <title>Script Defer Example</title></Head><Body>    <Scripttype= "Text/javascript"defer>Alert ("defer"); </Script>    <Scripttype= "Text/javascript">Alert ("Script"); </Script>    <Scripttype= "Text/javascript">window.onload= function() {alert ("Load");    }; </Script></Body></HTML>

Browsers that do not support defer properties have the following popup order: "Defer", "script", "load". deferon browsers that support properties, the order of popup is "script", "defer", and "load". Note that the defer element with the attribute is not followed by the <script> second, but onload is called before the event is triggered.

3, dynamic loading many JavaScript files, the browser does not guarantee the order of file loading. Load multiple JavaScript scripts with the Loadscript () function to ensure that the loading order

function () {    loadscript() (function () {        loadscript () {            alert ( "All Files is loaded!" );        });    });});

4. There are several ways to reduce the impact of JavaScript on performance:

    • Placing all the labels at the bottom of the <script> page, that is </body> , before closing the tag, ensures that the page has been rendered before the script executes.
    • Merge the scripts as much as you can. The fewer labels in the page <script> , the faster the load and the quicker the response. This is true for both the outer-chain script and the inline script.
    • A way to download JavaScript scripts without blocking:
    • Use <script> the defer attribute of the label (only for IE and Firefox version 3.5 or above);
    • Use dynamically created <script> elements to download and execute code;
    • Use the XHR object to download the JavaScript code and inject it into the page.

Detailed Link: https://www.ibm.com/developerworks/cn/web/1308_caiys_jsload/

Performance optimizations for "Digest" JavaScript: Loading and executing

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.