在Ubuntu中使用YUICompressor

Ubuntu

YUICompressor,是由Yahoo!提供的压缩(Minify)Javascript,CSS的工具。

YUICompressor是用Java写的,所以使用它之前必须先安装Jre:

sudo apt-get install sun-java6-jre

然后,下载YUICompressor-2.4.2.zip,并解压至任意位置。

参数说明

Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]

Global Options
-h, –help Displays this information
–type Specifies the type of the input file
–charset Read the input file using
–line-break
Insert a line break after the specified column number
-v, –verbose Display informational messages and warnings
-o Place the output into . Defaults to stdout.

JavaScript Options
–nomunge Minify only, do not obfuscate
–preserve-semi Preserve all semicolons
–disable-optimizations Disable all micro optimizations

提示:
其实不用输入–type js 或 –type css, YUICompressor也会根据文件后缀名来自动判断。

以下是我写的一段脚本:

#!/usr/bin/python

import os
import sys

compressor_path = '/home/allen/.tools/yuicompressor.jar'
charset_code = 'utf-8'

def compressor(file):
    os.path.splitext(file)
    return '-min'.join([os.path.splitext(file)[0], os.path.splitext(file)[1]])

files = sys.argv[1:]

for file in files:
    os.system('java -jar %s %s -o %s --charset %s --preserve-semi' % (compressor_path, file, compressor(file), charset_code))

把脚本以任意名字保存,如“压缩JS文件”,并将文件放到你的用户目录下的.gnome2/nautilus-scripts/目录中,如:/home/allen/.gnome2/nautilus-scripts/

这样你就可以更加方便的使用YUICompressor了~

Read More

Ubuntu 11.04 动物代号

Ubuntu

Ubuntu 11.04的动物代号将是:Natty Narwhal(聪慧的独角鲸)。

narwhal2 Ubuntu 11.04 动物代号

维基百科对Natty的解释是(informal) Smart and fashionable,也就是兼具头脑和外表。

独角鲸是生活在北极冰冷海域的小型鲸鱼,因为头部前段3米左右的螺旋形犄角状物而得名,长久以来被认为是传说中的独角兽的化身。然而传说终归是传说,独角鲸的“犄角”并非是角,只是一颗外露的长牙,披有神话色彩外衣的东西往往在现实中是不复存在的。独角鲸的“独角”没有纯洁净化的魔力,也无法使它们永生不死。但不可否认的是,它们成为了这世上绝无仅有,这般独特而美丽的生物。(摘自互动百科)

来源: http://article.yeeyan.org/view/140496/127197

Read More

无觅相关文章插件,快速提升流量