Use jsbuilder to compress your JavaScript/CSS source code

Source: Internet
Author: User

Jsbuilder2 (extjs.com/products/jsbuilder) is a newly released source code packaging tool for extjs 3. It is written in Java and packaged and compiled into jar format. The execution file is released to the programmer. As a packaging tool for auxiliary developers, it contains several open-source projects, including the rhino Project (famous JavaScript compiler) and Yui compressor (minification and obfuscation for JS/CSS compression ).
JSON encoder (from www.json.org) in the Java environment, which is easy to use in JavaScript and CSS projects. "Obfuscation" mainly relies on Yui compressor, because we know that JavaScript source code obfuscation is a "Top Priority" for the confidentiality of many projects. the Yui compressor algorithm should be very safe and provide a high level of obfuscation, such as the name of the mixed local variable.

Jsbuilder2 has the following features:

  • Cross-platform Java applications with simple usage
  • JSON-based configuration file structure
  • Use Yui compressor for File compression
  • Resource files can be easily migrated between the development and deployment phases

Unlike the first version of the GUI, jsbuilder2 is a command line-only tool, so we must understand its parameters. First, you must have java.exe to run the jar package. We usually add this command to the "environment variable", and then add the-jar parameter to run the jsbuilder2.jar file. For the jsbuilder parameter list, see:

  • -- Projectfile-P (mandatory) jsb2 file, which defines the specific packaging task. Location of A jsb2 project file
  • -- The main directory generated by homedir-D (required) is usually the directory for project deployment.
  • -- Verbose-V (optional parameter) Output detailed process in production.
  • -- Debugsuffix-s (optional parameter) for convenience of debugging, the subsequent name of the JS debugging file is produced. The default value is "debug" to indicate that this is the JS file used for debugging.
  • -- Help-H (optional parameter) displays help.

Usage on Windows:

Java-jar jsbuilder2.jar -- projectfile C:/apps/www/ext3svn/EXT. jsb2 -- homedir C:/apps/www/deploy/

Usage on Linux or OS X:

Java-jar jsbuilder2.jar -- projectfile/home/Aaron/www/trunk/EXT. jsb2 -- homedir/home/Aaron/www/deploy/

As mentioned above, the jsb2 file of jsbuilder is obviously a configuration file serving the second version, which is different from the old version. In the first version, *. JSB used an XML file as the configuration file. At that time, it was a program written by. Net winform. In this Java rewriting version, JSON is used as the configuration file format. We have mentioned that jsbuilder has both the rhino JS engine of moliza and the json.org package. It allows the JS engine to obtain the JSON object using the eval () function, and also allows the Java code to obtain this
JSON objects are convenient methods. Is it inconvenient to use XML? It is not necessarily because we can learn from the open-source information of rhino. The newer version of rhino is upgraded to JavaScript 1.8, which officially supports E4X (ecmascript (aka JavaScript) for XML, e4X. With E4X support, it is easy to convert XML into JavaScript objects. Of course, using XML is another thing.

The following describes the detailed list of JSON formats.

The top-level keys ):
Projectname String type Description of the project.
Deploydir String type The deployment directory specified by the command line. This directory is created in the homedir directory.
Licensetext String type Specify the header content for all JS and CSS, and use/N as a line break.
Pkgs Array type Array of package Descriptors
Resources Array type Resource descriptor Array
Package Descriptor (file descriptors :):
File String type Imported file.
Path String type Directory of the imported file.
Isdebug Bool type Whether to generate a debug version this configuration is currently not enabled (unused), so there will always be two versions of debugging and compression.
Filedocumdes Array type The file descriptor to be introduced in this package.
Pkgdeps Array type Package descriptor list. The behavior of this configuration depends on the configuration of includeps.
Includedeps Bool type Whether the output file contains dependent files. The default value is false.
Resource Descriptors)
SRC String type Source of the migrated Resource
Dest String type Destination of the moved Resource
Filters String type Create a regular expression that specifies how to filter files copied from SRC to DeST. All SVN and hidden files will be automatically excluded. Note that all/'s must be escaped //.
Resource Descriptor)
SRC String type Source of the migrated Resource
Dest String type Destination of the moved Resource
Filters String type Create a regular expression that specifies how to filter files copied from SRC to DeST. All SVN and hidden files will be automatically excluded. Note that all/'s must be escaped //.

From the list, we can see that the JSON format is still listed as key/value, key/key value. After we define our own configuration, save it as a file *. jsb2 for jsbuilder to read.

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.