This article mainly introduces the JavaScript analysis and compression tool JavaScriptAnalyser. If you need it, refer to the JSA compression process in two steps.
The first step is syntax compression, similar to Dojo ShrinkSafe, but more secure and effective than him.
Step 2: Text compression. Currently
JavaScript Compressor compression algorithm.
Http://dean.edwards.name/packer)
You can set these settings in the settings window.
By default, the file is compressed by syntax. When the file is larger than 90% bytes, and the text can still be compressed to the original size of, the original text is compressed.
The following example shows the JSA syntax compression and optimization functions.
The Code is as follows:
Try {
// Xxxx ();
}
Catch (e ){
Yyyy ();
Function f1 (){
}
}
Finally {
Zzzz ();
}
Function f2 (var1 ){
Var var2 = 2;
Var var3 = 3;
Var withObject = {var2:-2}
With (withObject ){
Alert (var2 );
}
}
Compress the results (formatted for easy reference ):
The Code is as follows:
Zzzz ();
Function f2 (){
Var var2 = 2;
Var B = 3;
Var C = {var2:-2 };
With (C ){
Alert (var2 );
}
}
Comparison with other compression tools:
1. JavaScript Compressor (http: // dean. edwards. name/packer /)
Take his own compression tool code as an example (v2.02). The packer size is 7,428 bytes after compression (comment removal ).
Our compression tool can be compressed to 7,256 bytes.
7256/7428 = 0.9768443726440496
2. Dojo ShrinkSafe)
Take the source code of the framework as an example (v0.4.1 ):
The compression size is 149,518 bytes, which can be reduced to 81,261 bytes after compression.
81261/149518 = 0.5434864029748927
Security description:
1. JavaScript Compressor
Text-based compression, I did not elaborate on the logic, but the possibility of such compression problems is very low, our compression tool also uses his compression algorithm, in JSI 1.1 a8 and
In the test of the third-party class library integrated by Alibaba Cloud, no exception was found. There are also well-known frameworks for JQuery, and I believe there will be no problem.
Supplement (): I found a bug in the analysis of multi-line string syntax in JavaScript. However, this problem will no longer exist after JSA syntax compression.
2. Dojo ShrinkSafe dangerous !!!!!
Replace the long local variable name with a short name. This is an extremely insecure compression tool. For example:
The Code is as follows:
Function (){
Var withObject = {variable1: 1}
Var variable1 = 2;
With (withObject ){
Alert (variable1 );
}
}
Compress:
The Code is as follows:
Function (){
Var _ 1 = {variable1: 1 };
Var _ 2 = 2;
With (_ 1 ){
Alert (_ 2 );
}
}
This is obviously incorrect. This spam does not pay attention to some special javascript syntaxes and is dynamic.
No processing is performed on eval functions, catch operations, and with statements.
In contrast, JSA is the most secure and effective compression tool I know.
JSA not only supports code compression, but also supports formatting and script analysis.
The script analysis function can be used to view the script information and find potential problems in the script.
For example, you can view the functions and variables in the script.
The external variables are used. And so on...