Publish an efficient JavaScript analysis, compression tool JavaScript Analyser_javascript tips

Source: Internet
Author: User
Tags javascript multiline string
Publish an efficient JavaScript analysis, compression tool JavaScript analyser
First, send a script compression example to show the JSA syntax compression and optimization features.
Copy Code code 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 results (formatted for ease of reference):

Copy Code code as follows:

Zzzz ();
function F2 (A) {
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 more efficient.

The second step is text compression, which is currently used
The compression algorithm for JavaScript compressor.
(http://dean.edwards.name/packer/)

These can be set in the Settings window.
The default is to use syntax compression, when the file is greater than 1000byte and text compression can still be compressed to the original size of 90% before the original text compression.


Compare with other compression tool compression rates:

1. JavaScript compressor (http://dean.edwards.name/packer/)
With his own compression tool code as an example (v2.02) Packer compressed after a size of 7,428 bytes (remove annotation).
And our compression tool can be compressed to 7,256 bytes.
7256/7428 = 0.9768443726440496
2.Dojo Shrinksafe (coarse things, both inefficient and dangerous, recommend the original users to quickly replace)
With his own framework source code for example (v0.4.1):
His own compression size is 149,518 bytes, and we can shrink to 81,261 bytes after compression.
81261/149518 = 0.5434864029748927


Security Note:
1.JavaScript Compressor
Based on text compression, I did not look at the logic, but the possibility of this compression problem is very low, our compression tool also uses his compression algorithm, in JSI 1.1 A8 and
No exceptions were found in the tests for its integrated Third-party class libraries. And there are well-known framework jquery use, I believe there will be no problem.

Add (2007-03-12): Found today, this thing has bugs when parsing JavaScript multiline string syntax. However, after JSA syntax compression, this problem will no longer exist.





2.Dojo SHRINKSAFE Dangerous!!!!!
Replacing a long local variable name with a shorter name is an extremely insecure compression tool that illustrates:



JavaScript code
function () {
var withobject = {Variable1:1}
var variable1 = 2;
With (Withobject) {
alert (VARIABLE1);
}
}


will be compressed into:
function () {
var _1={variable1:1};
var _2=2;
With (_1) {
alert (_2);
}
}



This is obviously wrong, this garbage does not pay attention to JavaScript certain special syntax, and dynamic nature.
For the Eval function, the catch operation, the WITH statement, nothing is handled.

By contrast, JSA is the safest and most effective compression tool I know today.
JSA not only provides code compression, but also can do format, script analysis.


The script profiling feature can be used to view script information and to find potential problems in the script.
For example, look at the statements in the script that declare those functions, variables.
Those external variables were used. Wait a minute...


Download Address:
http://sourceforge.net/project/showfiles.php?group_id=175776
Or
http://forum.xidea.org file List
Related Article

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.