How to optimize js

Source: Internet
Author: User

// Download Size Optimization:

I. compression tools

ESC-1.14

E: ESC-1.14> cscript esc. wsf-l 4-ow E: jssrc. js E: jsnew. js

-L leval level [0-4] 0 Merge multiple js, 1 comment 2 remove space 3 Remove line feed 4 simplify variable naming

-The first parameter after ow is the original file, and the second parameter is the post-execution file. Multiple files are separated by Spaces

Ii. When writing code

(1) Shorten the negative judgment obj! = Null =>! Obj

(2) define the Array var arr = new Array () ;=> var arr = [];

(3) define an empty Object var obj = new Object () ;=> var obj = {};

(4) define an object in JSon format

// Optimization of Running Efficiency

(1) do not forget var when defining variables; otherwise, it becomes a window object.

(2) Use local variables whenever possible

(3) Sending and switching cycles with High Performance

(4) do while has higher performance than while

(5) prioritize the use of built-in Methods

(6) store common values

(7) Saving on Dom. If you replace the table content of a div, it is better to change InnerHTML of div than to operate a large number of table dom.

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.