Compressing JavaScript file methods

Source: Internet
Author: User

write in front: when the front end of the formal deployment, JavaScript files generally need to compress, and generate the corresponding Sourcemap file, for some small project development, here is a simple way.

====== Body begins ======

1. Download the Google-closure-compiler file:

Download from here: Download

2. Copy the Compiler.jar from the compressed package to the directory of JavaScript files that need to be compressed.

3. Open the command line CMD,CD to the directory and run the following command:

Java-jar Compiler.jar--js test.js--js_output_file test.min.js--create_source_map test-min.js.map

(1) need to install Java Runtime environment.

(2)-jar parameter specifies the jar file, here is Compiler.jar

The--JS parameter specifies the JavaScript source file

The--js_output_file parameter specifies the compressed JavaScript file to be generated

The--create_source_map parameter specifies the source map file to generate

(3) Here is the Test.js source file is compressed into a test.min.js file, and a source map file is generated Test-min.js.map

4. Add the Soure Map reference description at the end of the compressed file (test.min.js).

@ sourcemappingurl=test-min.js.map

Note: after adding the source map reference description, the current side refers to the compressed version of the JS file, using Chrome's developer tool can still locate the specific error line number, you can change in the uncompressed file and then compress.

5. More usage:

(1) Compiling multiple JavaScript files:

The--JS parameter specifies multiple JavaScript source files, which are merged.

(2) View Help

  Java-jar Compiler.jar--help

Finish

Document Information

    • Copyright Disclaimer: Free Reprint-Non-commercial-non-derivative-maintain attribution (Creative Commons 3.0 license)
    • This article is for original articles, welcome reprint, follow up this blog will be updated constantly, so please keep this document information.
    • This address: http://www.cnblogs.com/wuguanglei/p/4782769.html

Compressing JavaScript file methods

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.