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

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.