Simple javascript performance problems and learning notes _ javascript skills

Source: Internet
Author: User
I recently read a book titled "high-performance javaScript" and found that many minor details exist in my javaScript writing. Although these problems do not cause program running errors, they may slow the interface loading, the user experience is poor, so let's take a closer look at the points that should be noted. 1. The fewer the script tags, the better. (although there are multiple tags, the program will not report errors ), because the page rendering is blocked during initial download of each script tag.
2. Do not place the script tag on the top of the page as much as possible.Because each script downloads the corresponding js file during execution, the browser will display the page only after all js/css downloads are complete.
3. When multiple js files need to be imported, we usually write two In fact, multiple data types can be imported at a time. For example:
4. The script tag has a property: defer, which indicates that the script contained in this element will not modify the DOM, so the code can be safely delayed, however, this attribute is only supported by IE4 + and Firefox3.5 + browsers. I hope you will note that other browsers will be ignored directly. Example:

, Test and verify the defer attribute example:

The Code is as follows:


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.