JS Compression Tools Yuicompressor Use Tutorials _javascript tips

Source: Internet
Author: User
JS,CSS compression tools provided by the cloud-dwelling community yuicompressor 2.46 Pack
Brief introduction
Official website: http://developer.yahoo.com/yui/compressor/
JS and CSS Compression tool yuicompressor
Current Latest Version: 2.4.2
The operation needs to install JDK First, official download address: http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html According to their own system to choose the appropriate version, generally 586 that can be.
Yuicompressor is written using pure Java, running with JDK1.4 or later, parsing and cutting the JavaScript source files based on Rhino. You can remove redundant whitespace characters (spaces, line breaks, tabs) from JavaScript files and CSS files, confuse them with JavaScript files, change the names of local variables, and convert them to characters of 1, 2 or 3, in short. For CSS, there is also a method of optimizing the value of the 0-valued attribute to optimize the color value of the compressed file.

Using tutorials
The following is an introduction to Yuicompressor using command-line methods.
Command line usage
Syntax: Java-jar yuicompressor-x.y.z.jar [Options] [input file]
General parameters:
-H,--help display Help information
--type <js|css> Specify the file type of the input file
--charset <charset> Specifies the encoding used to read input files
--line-break <column> Inserts a line-bread symbol after the specified column
-V,--verbose displays info and warn level information
-o <file> specify output files. The default output is the console.

JavaScript-specific parameters:
--nomunge only compresses and does not confuse local variables.
--preserve-semi keep all the semicolons.
--disable-optimizations prohibit optimization.

Using the example: Java-jar yuicompressor-2.4.2.jar-o d:/temp/hello_min.js hello.js
below this article is another Netizen writes, may refer to under.
Today for the site wrote a lot of JS code, looking at more and more code, can not help but a little bit of a panic, so the speed of the site will be very slow, suddenly remembered that before the pony said there is a JS compression tool, so asked the punk teacher, enthusiastic Teddy boy will pass the tool to me, and teach me how to use, a try, really good.
This is Yahoo's yuicompressor, very convenient, using the following methods:

Installation steps:

1. Unzip the Jsminifier.rar to X:\jsMinifier and add X:\jsMinifier to the system PATH environment variable (if you do not join path, you can manually modify the registry file to refer to the full path.)

2. Rename X:\jsMinifier\jsMinifier.tpl.reg as Jsminifier.reg, CssMinifier.tpl.reg as Cssminifier.reg. You can modify the configuration yourself (see 1).

3. Run Regedt32 to open Registry Editor, and then import Jsminifier.reg and Cssminifier.reg to the registry.


Test installation:

1. On the X:\jsMinifier\test.source.js Right-click, execute menu "compress JavaScript", the system generates X:\jsMinifier \test.js file automatically. If you perform a compression on the Test.js file again, the system generates a test-min.js file with the same content, which compresses the default file name for a source.js file.

2. CSS compression test is similar to 1.


Note: The tool can also compress CSS files
If it is downloaded from the http://www.jb51.net/jiaoben/25557.html file, download directly after decompression, run Install.bat, in need of compressed CSS or JS file above the right key to choose

A file with-min is generated after a file name in the same directory.

If you need to bulk compress files, you can refer to the following script
Batch processing script sharing under Windows (copy to Notepad, save as Bat, modify the path to apply):
Copy Code code as follows:

@echo off
:: Set YUI compressor start directory
SET Yuifolder=c:
:: Set your JS and CSS root directory, the script will automatically find and compress all JS and CSS at the tree level
SET Jsfolder=d:\webjsandcss
Echo is looking for JavaScript, CSS ...
CHDIR/D%jsfolder%
For/r. %%a in (*.js *.css) do (
The @echo is compressing%%~a ...
@java-jar%yuifolder%\yuicompressor-2.4.6.jar--charset UTF-8%%~fa-o%%~FA
)
echo Complete!
Pause & Exi

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.