JS. Compression and obfuscation.

Source: Internet
Author: User

One day, the front-end began code optimization. I am responsible for learning from you.

 

About code compression.

 

1. Compression tool classification.

 

Class 1: File compression. Gzip. Compress several files into a gz package. You can increase the speed when downloading code. Official website. This has been available for a long time and is still in use ~

 

Another type: remove the blank comment of the file. Such as JSMin, YUI Compressor, and Google Closure Compiler. There may be Dojo Compressor and so on.

 

2. a few details.

 

A. JSMin. No obfuscation is processed. (Obfuscation, simply put, refers to replacing the name of the variable function you define with a letter, which is shorter and is not known by others. Of course, obfuscation is not that simple ..)

 

Usage: JSMin <uncompressor. js> compressor. js ()

Note: js files are preferably in ASCII or UTF-8 format. But we are generally UTF-8 Oh.

The JSMin operation is irreversible. Save the source file and standardize the code. JSLint.

 

 

B. YUI Compressor. Based on Java (JRE.> 1.4 ). But it is better than JSMin compression. YUI can also compress CSS files.

 

Principle: Remove redundant spaces; shorten the variable name for JS; optimize the 0 value attribute value for CSS and optimize the color value (but not as good as CSSTidy: Support merging related attributes .)

Usage: java-jar yuicompressor-2.4.2.jar in. js-o out. js ()

Java-jar yuicompressor-2.4.1.jar -- nomunge -- preserve-semi -- disable-optimizations in. js-o out. js (no obfuscation, no semicolon, No optimization ..)

Java-jar yuicompressor-2.4.1.jar -- charset UTF-8 in. js-o out. js (UTF-8 encoding can be specified)

 

Others. You can refer to this remark. Some principles. (This article involves some knowledge points. For details, see the high-performance JS book .)

 

C. Google Closure Compiler. For details, see. The PPT of Yubo.

 

 

 

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.