JavaScript simple performance issues and learning notes

Source: Internet
Author: User

  is reading a book recently: "High-performance JavaScript", found that they usually write JS there are a lot of small details on the problem, although these problems will not cause the program to run error, but will lead to slow interface loading, user experience, then we will be careful to count the place to pay attention to it

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 not on the top of the page, Try to put in the bottom of the <body>, because each <script> in the implementation of the time, will download the corresponding JS file, the browser will wait for all js/css download completed to show the page   3, when you need to import multiple JS files, In general, we are writing two <script src= "..."/&gt, which in fact supports importing multiple at once, for example: <script src= "File1.js&file2.js"/>  4, < The script> tag has a property: defer, which indicates that the script contained in this element does not modify the DOM, so the code can safely defer execution, but this property is supported only by ie4+ and firefox3.5+ browsers, and I want you to be aware of it when you use it, if other browsers will be directly ignored, using examples:   <script type= "Text/javascript" src= "file1.js" defer/>    , test validation defer attribute example:   &N BSP; 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 understanding order: Defer, script, load, but if the order is in the browsers that support defer: script, defer, load , it should be noted that the defer does not follow the script, but is invoked before the OnLoad event is processed.   Time is limited, let's record so much 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.