JavaScript simple performance problems and learning notes _javascript skills

Source: Internet
Author: User

1, <script> label should be less the better (although there are many will not cause the program to complain), because each <script> tag initial download will block page rendering
2, <script> label as far as possible do not put on the top of the page, as far as possible in the <body> below, because each <script> in the implementation of the time, will download the corresponding JS file, the browser will wait for all js/ CSS download is complete before displaying the page
3, when the need to import a number of JS files, under normal circumstances, we are writing two <script src= "..."/>, in fact, to support a one-time import of multiple, such as: <script src= "File1.js&file2.js"/ >
4, <script> tag has a property: defer, this attribute indicates that the script contained in this element will not modify the DOM, so the code can safely delay execution, but this property only ie4+ and firefox3.5+ browser support, I hope you use the time to notice, If other browsers, it will be ignored directly, using the example:

<script type= "Text/javascript" src= "file1.js" defer/>

, test the Validation defer Property Example:

Copy Code code as follows:

<script Defer>alert ("defer");</script>
<script>alert ("script");</script>
<script>
Window.onload = function () {
Alert ("Load");
};
</script>

This code should be executed in our normal comprehension order: Defer, script, load, but if the order is script, defer, and load in the browsers that support defer, it should be noted that defer is not followed by script execution, Instead, it is invoked before the OnLoad event is processed.

Time is limited, so let's record it today.

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.