Comparison and solution of jQuery min package creation method and javascript Compression Method

Source: Internet
Author: User
Tags javascript eval
In the past two days, I want to use the pack javascript to sort out programs for friends, so I want to get a pack method that is the same as the jQuery min package and speed up loading. Of course, I am mainly curious. After turning around on the Internet, all the same articles are copied, and we cannot tell which one is original. In the future, the search engine will have the ability to search for original articles. Otherwise, the original author will be overwhelmed.
There is no proper answer to this question. The link is a dead link, and overseas websites are all irrelevant descriptions. A bunch of tools have been installed from CSDN, which is not easy to use. Of course, I finally figured it out as follows.
Javascript is a scripting language. If it is out of the way, it cannot be recognized by the interpreter. Therefore, whether it is encryption, compression, or obfuscation, the final result must be understood by the parser. To sum up, the original Javascript has the following transformations,

 

  • Encryption: Microsoft has a control that can encrypt javascript. After encryption, it cannot be read at all. You need to use this control to decrypt it during running. The encryption and decryption process is reversible, so some basic people can still crack it. In addition, this control reports a security warning when running in the browser, and only applies to IE, so it is of little use.
  • Shelling: Some tools can package js files into exe files, which is similar to running with cscript/wscript at runtime. Such a method won't work in the webpage.
  • Redundancy: Remove comments, line breaks, and useless empty characters in javascript. This method has no technical content. If there is no comments, you can use the editor.
  • Reorganization: The javascript eval function and regular expression are used to reassemble the source file. This process is reversible. The restructured file can only be used by cainiao, which affects the loading efficiency.
  • Compression: This is the focus. Let's take a look at jQuery's min package. In addition to de-redundancy, the main part of the variable inside the function is also replaced, in this way, you can minimize the file length without considering reading. This process is also very technical, because the global variables cannot be modified, otherwise the compressed file may not be used. The specific implementation method seems to have been transferred a lot on the Internet. In fact, there is only one, yuicompressor. I checked it on jQuery's SVN and found this package in the build directory, the current version is 2.4.2.

Therefore, if you want to compress javascript, or are just as curious as I do, you can get a yuicompressor to play with it. I specifically use jQuery. js tried it and processed files and jQuery. min. js exactly.

 

The original address is unknown.

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.