How to optimize JS: JS optimization

Source: Internet
Author: User
Tags define array object define null variable

Optimization of Download size:
One: Compression tool compression
ESC-1.14
E:\esc-1.14>cscript esc.wsf-l 4-ow E:\js\src.js E:\js\new.js
-L Leval level [0-4] 0 Merge multiple js, 1 go to comment 2 go to space 3 Remove line 4 simplify variable naming
The first argument after-ow is the original file, and the second parameter is the post-execution file. Multiple file spaces separated
Second: When writing code
(1) shortening the negative judgment Obj!=null =>!obj
(2) define the array var arr=new array (); => var arr=[];
(3) Define null object var Obj=new object (); => var obj={};
(4) Defining JSON-formatted objects
Optimization of operating efficiency
(1) Define variable don't forget Var, otherwise become window object
(2) Use local variables as far as possible
(3) Circulation, high performance
(4) doing while ratio while performance is high
(5) Priority to use the built-in method
(6) Storing common values
(7) Save the use of DOM. If you replace a div's table content, changing the innerHTML of the div is better than a lot of manipulating table DOM performance
This article links http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20130323/37343.html

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.