星期四, 十月 29, 2009
使用 YUI Compressor 壓縮 CSS / JavaScript
使用 Yahoo! 提供的 YUI Compressor 來壓縮(Minify) JavaScript 和 CSS.
註: 此文件操作環境於 Ubuntu / Debian Linux.
官方文件
- 官方網頁: YUI Compressor - YUI Compressor - The Yahoo! JavaScript and CSS Compressor
- 說明文件: YUI Compressor README
環境設定
- 安裝 Java 執行環境: apt-get install sun-java6-jre
- 下載 yuicompressor-2.4.2.zip
- unzip yuicompressor-2.4.2.zip
壓縮 JavaScript
- java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js --charset utf-8 --type js
壓縮 CSS
- java -jar yuicompressor-x.y.z.jar myfile.css -o myfile-min.css --charset utf-8 --type css
範例
- # 不用輸入 --type js / css, yuicompressor 依照檔名也會自動判斷.
- java -jar yuicompressor-2.4.2.jar myfile.js -o myfile-min.js --charset utf-8 --preserve-semi # 保留分號(--preserve-semi)
- java -jar yuicompressor-2.4.2.jar myfile.css -o myfile-min.css --charset utf-8
參數說明
Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]
Global Options
-h, --help Displays this information
--type <js|css> Specifies the type of the input file
--charset <charset> Read the input file using <charset>
--line-break <column> Insert a line break after the specified column number
-v, --verbose Display informational messages and warnings
-o <file> Place the output into <file>. Defaults to stdout.
JavaScript Options
--nomunge Minify only, do not obfuscate
--preserve-semi Preserve all semicolons
--disable-optimizations Disable all micro optimizations
延伸閱讀
- Vim 的 JavaScript 縮排格式最佳化 外掛
- YUI (Yahoo! User Interface) Combo handling 匯整壓縮
- 自動幫 JavaScript / CSS 檔加上版本編號
- 在WindowsXP安裝各種版本的IE
- Reset CSS - 取消 Html 原有樣式
相關標籤
Closure from Google does similar thing.
可以用Closure 啦!基本上 所有Yahoo 或Microsoft 提供的 Google 都有 也都會提供
Comment by
Git Trac
(11/06/2009 22:07)
發表迴響
PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~




