The compression process of JSA is divided into two steps
The first step is syntax compression, similar to Dojo ShrinkSafe, but safer than it and more efficient.
The second step is text compression, currently
JavaScript Compressor compression algorithm.
(http://dean.edwards.name/packer/ )
These can be set in the Settings window.
By default, syntax compression is first used. Text compression is used on the original basis when the file is larger than 1000byte and text compression can still be compressed to 90% of the original size.
Here is a script compression example to show JSA syntax compression and optimization functions.
The code copy 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);
}
}
Compressed results (formatted for easy access):
The code copy is as follows:
zzzz();
function f2(A) {
var var2 = 2;
var B = 3;
var C = {var2:-2};
with (C) {
alert(var2);
}
}
Comparison with other compression tools for compression ratios:
1. JavaScript Compressor(http://dean.edwards.name/packer/)
With his own compression tool code as an example (v2.02) Packer compressed with size 7,428 bytes (remove comments).
And our compression tool can be compressed to 7,256 bytes
7256 / 7428 = 0.9768443726440496
2.Dojo ShrinkSafe (Rough things are both inefficient and dangerous. It is recommended that the original user change it as soon as possible)
With his own framework source code as an example (v0.4.1):
It compresses the size to 149,518 bytes by itself, and we can shrink it to 81,261 bytes after compression
81261 / 149518 = 0.5434864029748927
Safety instructions:
1.JavaScript Compressor
Based on text compression, I did not look at the logic in it carefully, but the possibility of this compression problem is very low. Our compression tool also uses its compression algorithm, in JSI 1.1 a8 and
No exception was found in the test of its integrated third-party library. And there is also a well-known framework JQuery, so I believe there will be no problem.
Supplement (2007-03-12): Today I found that this thing has a bug when analyzing JavaScript multi-line string syntax. However, this problem will no longer exist after being compressed by JSA syntax.
2.Dojo ShrinkSafe Dangerous! ! ! ! !
Replace the long local variable name with a shorter name, which is an extremely unsafe compression tool, for example:
The code copy is as follows:
function(){
var withObject = {variable1:1}
var variable1 = 2;
with(withObject){
alert(variable1);
}
}
Compress to:
The code copy is as follows:
function(){
var _1={variable1:1};
var _2=2;
with(_1){
alert(_2);
}
}
This is obviously wrong, this garbage doesn't pay attention to some special syntax, and dynamics of JavaScript.
No processing is done for eval functions, catch operations, and with statements.
In contrast, JSA is the safest and most effective compression tool I know at present.
JSA not only provides code compression functions, but also can be used for formatting and script analysis.
Script analysis can be used to view script information and find potential problems in scripts.
For example, check the functions and variables declared in the script.
Those external variables were used. etc. . .