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.