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.