Use Yui compressor to compress ext JS and CSS (right-click batch processing and packaging are supported)

Source: Internet
Author: User

 

Yui compressor is a JavaScript and CSS compression tool released by Yahoo. It runs in a Java environment. Therefore, you must first install JRE or JDK (here I use JDK ).

1. Java environment configuration-windows7 (32-bit)

1) download and install JDK (version 1.6 or later is recommended). My JDK installation directory is D: \ Program Files \ Java \ jdk1.6.0 _ 27

Http://www.oracle.com/technetwork/java/javase/downloads/index.html

2) Configure Java User Variables

Computer -- properties -- Advanced System settings, Open"System attributes"Window, select"AdvancedTab

Click"Environment Variable", Open the" environment variable "window, and then set"System Variables"

A. NewJava_homeSystem Variables

D: \ Program Files \ Java \ jdk1.6.0 _ 27 (JDK installation path)

B. EditPathSystem variable (the default value already exists in the system, so add it before the default value. Remember: do not add a semicolon after the second bin)

% Java_home % \ bin; % java_home % \ JRE \ bin

C. CreateClasspathSystem Variables

.; % Java_home % \ Lib \ tools. Jar

3) start -- cmd, open the Command Prompt window, and enterJavacIf the following message is displayed, the installation is successful.

InputJava-versionTo view the Java version information.

 

2. UseYui CompressorCompressing JS or CSS files

1) downloadDecompress Yui compressor and findYuicompressor-2.4.6\ Build \Yuicompressor-2.4.6.jar zip, copy it to the specified location on disk (for example: F :\Yuicompressor-2.4.6.jar)

2)Start-search box-cmd, open the command window

3)InputJava-jar [yuicompressor-2.4.6.jar path] -- type [compressed file format JS or CSS] -- charset UTF-8 [uncompressed file path]-O [compressed output file path]Press enter to compress the JS or CSS file in the specified output directory.

Note:

-Type: Specifies the file type to be packaged. The options include JS and CSS.
-Charset: Character Set
-O specifies the output file name. If this parameter is not specified, the compressed content will be output to the command line.
For example, to compress a JS file, the statement is as follows:

Java-jar "F: \ yuicompressor-2.4.6.jar" -- Type JS -- charset UTF-8 "F: \ serviceapi \ JS \ QueryParamPanel-debug.js"-o "F: \ QueryParamPanel-min.js"

To compress the CSS file, you only need to change the JS file after-type to CSS, and specify the source file path and output path of the CSS file.

3. Create a batch processing tool

Yuicompressor-2.4.6.jar compressed package path: F: \ yuicompressor-2.4.6.jar

1) yuicompressor. BAT:

Cd "% 1"
For/F % A in ('dir/B *-min. js') Do call: processdel: %
For/F % A in ('dir/B * -min.css ') Do call: processdel: %
For/F % A in ('dir/B *. js') Do call: processcompress: %
For/F % A in ('dir/B *. CSS ') Do call: processcompress: %
: Processdel
If not [% 1] = [] Call: deleteminfiles: % 1
Goto: EOF
: Processcompress
If not [% 1] = [] Call: compressfiles: % 1
Goto: EOF
: Deleteminfiles
If exist "% Cd % \ % 1" Del "% Cd % \ % 1"
Goto: EOF
: Compressfiles
Java-jar "F: \ yuicompressor-2.4.6.jar" % 1-o % ~ N1-min % ~ X1
Goto: EOF

 

Enter the above batch processing code in the text editor and save itYuicompressor. bat batch file

 

2) yuicompressor. reg registry file code:

Windows Registry Editor Version 5.00
[Hkey_classes_root \ directory \ shell \ compress JS/CSS files]
@ = "Yui-compressor JS/CSS"
[Hkey_classes_root \ directory \ shell \ compress JS/CSS files \ command]
@ = "F: \ yuicompressor. Bat % 1"

Enter the above batch processing code in the text editor and save itYuicompressor. reg registry file

Note:

Yui-compressor JS/CSS-right-click the batch processing operation and choose menu item name
F: \ yuicompressor. bat -- yuicompressor. bat batch file path

3) double-click the Registry file to import it to the Registry. After selecting the folder,Right-click menu, An option is added.Yui-compressor JS/CSS]

4) Right-click the folder containing the JS file and choose "Yui-compressor JS/CSS" to start compressing all JS and CSS files in the folder, add-min after the source file name and save it as a new file.

 

4. Create and compress batch files

The file is as follows:
Batch files: pack-js.bat
Directory files to be packaged: pack-list.txt

Pack-js.bat code:

For/F % I in (pack-list.txt) do type % I> pack-all.js
Java-jar "F: \ yuicompressor-2.4.6.jar" -- Type JS -- charset UTF-8 pack-all.js-O pack-all-min.js

Pack-list.txt

Ext-basex-debug.js
AjaxRequest-debug.js
ServiceURL-debug.js
PagingStore-debug.js

Workspace-debug.js
DataCatalog-debug.js
MeasureTool-debug.js

 

Usage:
Put these two files in the current JS folder, run the pack-js.bat and package it into a compressed file pack-all-min.js

 

From: http://www.cnblogs.com/heiniuhaha/archive/2011/06/15/YUI-Compressor.html

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.