Read high-performance JavaScript programming Chapter I.

Source: Internet
Author: User
Tags script tag

Read the first chapter, although the translation is also feel up posture,

Let me summarize:

Because most browsers are single process UI Updatas and JS Execute

Then the problem arises: JS (script tag) would blocking page processing

Speak:

So everybody think about it.

Three ways of thinking about it.

1, Parallel downloads, then execute parallel download, then execute.

2, Download times less,less Download file less small amount (fine reduction)

3, add script dynamically, inject script (use XMLHttpRequest).

Other:

defer eg:<script type= "Text/javascript" src= "File1.js" defer></script>

The corresponding JavaScript file will be parsed in <script>
When the download is started, but the code is not executed until the DOM load is complete (before the OnLoad event handle is called)

Put JS references on </body> (many people know but don't understand why)

Cause: In head, you'll see the block is all over the white page.

There's something on the page at the bottom of the block. Haha good simple ~ Put the script at the base is the law

At last

The best thing is to use the wheels that others have made:

1, YUI3 2, the Lazyload Library 3, the LABJS library The second and third look very cool looks the third one is recommended.

You can also experience the refreshing writing of a chain-structured structure.

eg

<script type= "Text/javascript" src= "Lab.js" ></script>
<script type= "Text/javascript" >
$LAB. Script ("First-file.js"). Wait ()//This wait is the order in which JS is guaranteed to be executed (note: not fully downloaded, download is parallel)
. Script ("The-rest.js")
. Wait (function () {
Application.init ();
});
</script>

Read high-performance JavaScript programming Chapter I.

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.