High performance JavaScript (high-performance JavaScript) reading notes analysis _javascript tips

Source: Internet
Author: User
Chapter I: Loading and executing

The browser's JavaScript engine is the compiler layer optimization;
When a browser executes JavaScript code, it cannot do anything else at the same time (a single process), meaning that every time the <script> tag appears, it will be overbearing to parse and execute the script (each file must wait until the previous file is downloaded and executed before it starts downloading), So the head of JS and CSS used to render the page, interactive behavior (almost all) JS placed at the <body> bottom;
Mainstream browsers are allowed to download JS in parallel.
Reduce the number of external chain scripts will improve performance (merge JS)
Any web site can obtain any number of files by using a URL that is merged with a file.
Defer property can delay script (only IE4 and FF3.5 support)
Chapter II: Data Access

There are four basic data access locations in javascript: Direct, variable, array elements (indexed by numbers), and object members (indexed by a character bed).
Access to both direct and local variables is the fastest, whereas access to array elements and object members is relatively slow.
The deeper the position of a property or method in the prototype chain, the slower the speed at which it is accessed.
In general, you can improve JavaScript performance by using common objects, array elements, and saving them in local variables across variables.
Chapter III: DOM programming

Dom operations are fast in the WebKit kernel browser, and other browsers innerHTML fast.
Accessing and manipulating the DOM is an important part of modern web applications. But every bridge between the two islands of the link ECMAScript and Dom will be charged a ' bridge fee '.
Be aware of the return and rearrangement.
In IE: hover can reduce the response speed.
Fourth chapter: Algorithm and Process Control

Avoid using the for-in loop unless you need to traverse an object with a number of attributes.
Learn about stack overflow errors.
Fifth chapter: Strings and regular Expressions

Backtracking is not only the basic component of regular expression matching function, but also the inefficient source of regular expression.
the Sixth chapter: Quick Response User Interface

No JavaScript task should execute more than 100 milliseconds.
WEB workers is a feature that is supported by a new browser.
No JavaScript code is important to the extent that it can affect the user experience.
Seventh Chapter: Ajax

JSON is a lightweight data format that is faster to parse.
Reduce the number of requests by merging JS and CSS, as well as IMG.
Shorten the page load time, the main content of the page after loading completed, using AJAX to obtain those secondary files.
Eighth chapter: Programming Practice

Most of the time, there is no need to use eval () and function (), so it is best to avoid using them. As for settimeout () and SetInterval (), it is recommended that you pass the function instead of the string as the first argument.
There are several ways to create objects and arrays in JavaScript, but using object and array direct quantities is the quickest way (the more object attributes and array items, the more obvious the benefits of using direct amounts).
Do not repeat work: deferred loading, conditional preload.
Use the native method more because it is faster.
Nineth Chapter: Building and Deploying high-performance JavaScript applications

PV (Page view) is the number of pages viewed or clicked.
Reduce the number of HTTP requests required for page rendering, especially for those who first visit the site.
JavaScript compression.
JavaScript caching.
Using Content distribution networks (CDN)
The tenth chapter mainly introduces tools: such as Firebug,yslow, and some performance analysis.

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.