用yuicompressor来压缩你的js、css代码

据说用yuicompressor压缩出来的东东经gz压缩后体积比其它工具更小。
下载:http://yuilibrary.com/downloads/#yuicompressor
目前的最新版本是2.4.2

使用举例:
(确保你已经安装了jre ,并且将jar文件放在与js同一个目录,不然你打命令时就要连路径一起打了。 :mrgreen: )

1
java -jar yuicompressor-2.4.2.jar ihacklog.com.js -o ihacklog.min.js --charset utf-8 -v --type js

文档:
http://www.julienlecomte.net/yuicompressor/README

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
==============================================================================
YUI Compressor
==============================================================================

NAME

  YUI Compressor - The Yahoo! JavaScript and CSS Compressor

SYNOPSIS

  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

DESCRIPTION

  The YUI Compressor is a JavaScript compressor which, in addition to removing
  comments and white-spaces, obfuscates local variables using the smallest
  possible variable name. This obfuscation is safe, even when using constructs
  such as 'eval' or 'with' (although the compression is not optimal is those
  cases) Compared to jsmin, the average savings is around 20%.

  The YUI Compressor is also able to safely compress CSS files. The decision
  on which compressor is being used is made on the file extension (js or css)

GLOBAL OPTIONS

  -h, --help
      Prints help on how to use the YUI Compressor

  --line-break
      Some source control tools don't like files containing lines longer than,
      say 8000 characters. The linebreak option is used in that case to split
      long lines after a specific column. It can also be used to make the code
      more readable, easier to debug (especially with the MS Script Debugger)
      Specify 0 to get a line break after each semi-colon in JavaScript, and
      after each rule in CSS.

  --type js|css
      The type of compressor (JavaScript or CSS) is chosen based on the
      extension of the input file name (.js or .css) This option is required
      if no input file has been specified. Otherwise, this option is only
      required if the input file extension is neither '
js' nor 'css'.

  --charset character-set
      If a supported character set is specified, the YUI Compressor will use it
      to read the input file. Otherwise, it will assume that the platform'
s
      default character set is being used. The output file is encoded using
      the same character set.

  -o outfile
      Place output in file outfile. If not specified, the YUI Compressor will
      default to the standard output, which you can redirect to a file.

  -v, --verbose
      Display informational messages and warnings.

JAVASCRIPT ONLY OPTIONS

  --nomunge
      Minify only. Do not obfuscate local symbols.

  --preserve-semi
      Preserve unnecessary semicolons (such as right before a '}') This option
      is useful when compressed code has to be run through JSLint (which is the
      case of YUI for example)

  --disable-optimizations
      Disable all the built-in micro optimizations.

NOTES

  + If no input file is specified, it defaults to stdin.

  + The YUI Compressor requires Java version >= 1.4.

  + It is possible to prevent a local variable, nested function or function
    argument from being obfuscated by using "hints". A hint is a string that
    is located at the very beginning of a function body like so:

    function fn (arg1, arg2, arg3) {
        "arg2:nomunge, localVar:nomunge, nestedFn:nomunge";

        ...
        var localVar;
        ...

        function nestedFn () {
            ....
        }

        ...
    }

    The hint itself disappears from the compressed file.

  + C-style comments starting with /*! are preserved. This is useful with
    comments containing copyright/license information. For example:

    /*!
     * TERMS OF USE - EASING EQUATIONS
     * Open source under the BSD License.
     * Copyright 2001 Robert Penner All rights reserved.
     */

    becomes:

    /*
     * TERMS OF USE - EASING EQUATIONS
     * Open source under the BSD License.
     * Copyright 2001 Robert Penner All rights reserved.
     */

AUTHOR

  The YUI Compressor was written and is maintained by:
      Julien Lecomte <jlecomte@yahoo-inc.com>
  The CSS portion is a port of Isaac Schlueter's cssmin utility.

COPYRIGHT

  Copyright (c) 2007-2009, Yahoo! Inc. All rights reserved.

LICENSE

  All code specific to YUI Compressor is issued under a BSD license.
  YUI Compressor extends and implements code from Mozilla'
s Rhino project.
  Rhino is issued under the Mozilla Public License (MPL), and MPL applies
  to the Rhino source and binaries that are distributed with YUI Compressor.

喜欢这篇文章吗?

请订阅本站 RSS feed填写您的邮件地址,订阅我们的精彩内容:

相关日志

回复 (11)

  1. 54dev  / 回复

    你好,可以和贵站换个链接么?

    • 荒野无灯  / 回复

      去你博客看了,都是喜欢折腾的人啊。目前我已经不交换友情链接了。详细说明可见about页面。不过,不交换友情链接并不是不加链接 :cool:

  2. Leyond  / 回复

    呵呵,那你帮我看看这个插件叫什么啊?那个download as pdf 的很不错,

  3. 叶子  / 回复

    暂时看不懂,以后再研究

  4. qlj  / 回复

    呵呵。。 是啊。。 不过。。我每次来。。貌似 主题都不一样。。 哈。。

  5. qlj  / 回复

    是以前hacklog.cn 的么?

发表评论 修改评论取消编辑

允许使用的标签 - 您可以在评论中使用如下的 HTML 标签以及属性。

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

引用通告 (0)

› 尚无引用通告。

开灯