Notes on front-end javascript Performance Optimization

Source: Internet
Author: User


1. Code Efficiency
Variable usage Optimization
Declare objects and Arrays Using literal, such as var newarray =
[]; Var newobject = {var p1: 'T'; vat f1: function (){}}

Js searches for variables using the variable scope chain. If it is often used in the outer scope, temporary variables can be used instead.
For example

 


Write

Tbody =


No
For optimization use reverse loops for (var I = length; I --;)
Auto-false if I is reduced to zero to reduce a judgment.

Dom usage Optimization

Cache the length of the set in an intermediate variable. On the one hand, the access is faster, and the length of the set is changed.

Dom optimization also tries to use intermediate variables for repeated variables as much as possible,
Avoid repeated repainting and relayout
Use event Delegate technology to minimize the number of event handles


The length in HTMLcollect is constantly accessed, and the cycle changes are also changed.

UI process optimization

Page reality and js parsing use the same ui process, so the script running time should be controlled within MS as much as possible. If the time is too long, use settimeOut to split the program.

Workers can also be used in html5.
Others:
Eval not required
Do not use eval-like functions in setTimeOut, setInterval, and Function. Use the native method whenever possible.
2. Code Location and deployment

To avoid js blocking, js is usually placed at the end of the page. Compress js. Merge JavaScript. Use cdn.
3. Tools
Yslow
Pagespeed

Http://www.cleancss.com/

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.