Analysis of High Performance JavaScript (High Performance JavaScript) Reading Notes

Source: Internet
Author: User

Chapter 1: loading and execution

The JavaScript engine of the browser is optimized at the compiler layer;
When the Browser executes JavaScript code, it cannot do anything else (single process) at the same time ), this means that every time the <script> tag appears, it leads to parsing and executing pages with scripts (each file starts to be downloaded only after the previous file is downloaded and executed ), therefore, JavaScript and CSS in the header are used to render pages. JS with interactive behavior (almost all) is placed at the bottom of <body>;
Mainstream browsers allow parallel download of JS.
Reducing the number of external link scripts will improve the performance (merge JS)
Any website can use a URL that combines the specified files to obtain any number of files.
Defer attributes can be delayed scripts (only supported by IE4 and FF3.5)
Chapter 2: Data Access

JavaScript has four basic Data Access Locations: Direct Volume, variables, array elements (Indexed by numbers), and object members (Indexed by character beds ).
Direct access and local variables are the fastest. On the contrary, access to array elements and object members is relatively slow.
The deeper the location of an attribute or method in the prototype chain, the slower the access speed.
Generally, JavaScript performance can be improved through common objects, array elements, and stored in local variables across variables.
Chapter 3: DOM Programming

DOM operations are fast in webkit kernels, while innerHTML in other browsers is fast.
Accessing and operating DOM is an important part of modern WEB applications. However, each bridge between the ECMAScript and DOM islands is charged as a 'bridge payby '.
Pay attention to recovery and rescheduling.
In IE: hover reduces the response speed.
Chapter 4: algorithm and Process Control

Avoid using the for-in loop unless you need to traverse an object with the number of attribute locations.
Understand stack overflow errors.
Chapter 5: strings and Regular Expressions

Backtracking is not only a basic component of the regular expression matching function, but also the source of inefficient regular expressions.
Chapter 6: Quick Response user interface

No JavaScript task should be executed for more than 100 milliseconds.
Web workers is a feature supported by new browsers.
No JavaScript code is important to the extent that it can affect user experience.
Chapter 7: Ajax

JSON is a lightweight data format with fast resolution.
Reduce the number of requests by merging JS and CSS, and IMG.
The page loading time is shortened. After the main content of the page is loaded, Ajax is used to obtain the secondary files.
Chapter 8: programming practices

In most cases, you do not need to use eval () and Function (), so it is best to avoid using them. As for setTimeout () and setInterval (), we recommend that you pass in a function instead of a string as the first parameter.
There are many ways to create objects and arrays in JavaScript, but using objects and arrays is the fastest way (the more object attributes and array items, the more obvious the benefits of using direct traffic ).
Do not repeat work: delayed loading; conditional pre-loading.
Use more native methods because it is faster.
Chapter 9: build and deploy High-Performance JavaScript applications

PV (page view) is the page views or clicks.
Reduce the number of HTTP requests required for page rendering, especially for users who visit the website for the first time.
JavaScript compression.
JavaScript cache.
Use Content Delivery Network (CDN)
Chapter 10 describes tools such as firebug, YSlow, and performance analysis.

Related Article

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.