Publish an efficient JavaScript parsing, compression tool JavaScript analyser

Source: Internet
Author: User

Publish an efficient JavaScript parsing, compression tool JavaScript Analyser First a script compression example, showing the JSA syntax compression and optimization features.
  1. try {
  2. XXXX ();
  3. }
  4. catch (e) {
  5. YYYY ();
  6. Function F1 () {
  7. }
  8. }
  9. finally {
  10. Zzzz ();
  11. }
  12. function F2 (var1) {
  13. var var2 = 2;
  14. var var3 = 3;
  15. var withobject = {Var2:-2}
  16. With (Withobject) {
  17. alert (VAR2);
  18. }
  19. }

Compression results (formatted for ease of reference):

    1. Zzzz ();
    2. function F2 (A) {
    3. var var2 = 2;
    4. var B = 3;
    5. var C = {Var2:-2};
    6. With (C) {
    7. alert (VAR2);
    8. }
    9. }

The compression process of the JSA is divided into two steps

The first step is syntax compression, similar to Dojo Shrinksafe, but is safer and more effective than he is.

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

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

Compare compression ratios with other compression tools:

1. JavaScript Compressor (http://dean.edwards.name/packer/)
With his own compression tool code example (v2.02), the size of the packer is 7,428 bytes after compression (removal of comments).
And our compression tool can be compressed to 7,256 bytes
7256/7428 = 0.9768443726440496
2.Dojo Shrinksafe ( coarse things, both inefficient and dangerous, suggest that the original user quickly replaced)
With his own framework source code for example (v0.4.1):
His own compression size is 149,518 bytes, and we can compress it down to 81,261 bytes
81261/149518 = 0.5434864029748927

Security Instructions:

1.JavaScript Compressor
Text-based compression, I did not look closely at the logic, but the probability of this compression problem is very low, our compression tool also used to his compression algorithm, in JSI 1.1 A8 and
No exceptions were seen in the tests of its integrated third-party class libraries. And there is a well-known framework jquery use, I believe there will be no problem.

Supplement (2007-03-12): Found today, this thing is a bug when parsing JavaScript multi-line string syntax. However, this problem will not exist after JSA syntax compression.

2.Dojo Shrinksafe  Dangerous!!!!!
Replacing long local variable names with shorter names is an extremely unsafe compression tool, for example:

JavaScript code
    1. function () {
    2. var withobject = {Variable1:1}
    3. var variable1 = 2;
    4. With (Withobject) {
    5. alert (VARIABLE1);
    6. }
    7. }
Will compress into:
    1. function () {
    2. var _1={variable1:1};
    3. var _2=2;
    4. With (_1) {
    5. alert (_2);
    6. }
    7. }


this is obviously wrong., this garbage does not pay attention to some special syntax, and dynamics of JavaScript.
No processing is done for the Eval function, catch operation, with statement.

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

The script analysis feature can be used to view script information and to find potential problems in the script.
For example, the view script declares those functions, variables.
Those external variables are used.  Wait a minute... :
http://sourceforge.net/project/showfiles.php?group_id=175776

Publish an efficient JavaScript parsing, compression tool JavaScript analyser

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.