Publish an efficient JavaScript analysis and compression tool JavaScript analyser

Source: Internet
Author: User

Publish an efficient JavaScript analysis and compression tool JavaScript analyser
A script compression example is provided to show the JSA syntax compression and optimization functions. CopyCode 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 ):

Copy code The Code is as follows: zzzz ();
Function F2 (){
VaR var2 = 2;
VaR B = 3;
VaR c = {var2:-2 };
With (c ){
Alert (var2 );
}
}

The JSA compression process is divided into 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 CompressionAlgorithm.
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.

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)
With his own frameworkSource codeFor 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:

JavaScript code
Function (){
VaR withobject = {variable1: 1}
VaR variable1 = 2;
With (withobject ){
Alert (variable1 );
}
}

Compress:
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...

:
Http://sourceforge.net/project/showfiles.php? Group_id = 175776
Or
Http://forum.xidea.org file list

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.