-
Notifications
You must be signed in to change notification settings - Fork 151
/
README
129 lines (87 loc) · 4.14 KB
/
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
JSMin, The JavaScript Minifier
Douglas Crockford
2013-02-25
JSMin is a filter that removes comments and unnecessary whitespace from
JavaScript files. It typically reduces filesize by half, resulting in faster
downloads. It also encourages a more expressive programming style because it
eliminates the download cost of clean, literate self-documentation.
What JSMin Does
JSMin is a filter that omits or modifies some characters. This does not change
the behavior of the program that it is minifying. The result may be harder to
debug. It will definitely be harder to read.
JSMin first replaces carriage returns ('\r') with linefeeds ('\n'). It replaces
all other control characters (including tab) with spaces. It replaces comments
in the // form with linefeeds. It replaces comments in the /* */ form with
spaces. All runs of spaces are replaced with a single space. All runs of
linefeeds are replaced with a single linefeed.
It omits spaces except when a space is preceded and followed by a non-ASCII
character or by an ASCII letter or digit, or by one of these characters:
\ $ _
It is more conservative in omitting linefeeds, because linefeeds are sometimes
treated as semicolons. A linefeed is not omitted if it precedes a non-ASCII
character or an ASCII letter or digit or one of these characters:
\ $ _ { [ ( + -
and if it follows a non-ASCII character or an ASCII letter or digit or one of
these characters:
\ $ _ } ] ) + - " '
No other characters are omitted or modified.
JSMin knows to not modify quoted strings and regular expression literals.
JSMin does not obfuscate, but it does uglify.
Before:
// is.js
// (c) 2001 Douglas Crockford
// 2001 June 3
// is
// The -is- object is used to identify the browser. Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be
// Mozilla 4. Netscape 6 claims to be version 5.
// Warning: Do not use this awful, awful code or any other thing like it.
// Seriously.
var is = {
ie: navigator.appName == 'Microsoft Internet Explorer',
java: navigator.javaEnabled(),
ns: navigator.appName == 'Netscape',
ua: navigator.userAgent.toLowerCase(),
version: parseFloat(navigator.appVersion.substr(21)) ||
parseFloat(navigator.appVersion),
win: navigator.platform == 'Win32'
}
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
is.ie = is.ns = false;
is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0) {
is.ie = is.ns = false;
is.gecko = true;
}
After:
var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}
Character Set
JSMin requires, but does not verify, that the character set encoding of the
input program is either ASCII or UTF-8. It might not work correctly with other
encodings.
Caution
Be sure to retain your original source file. JSMin is a one-way trip: Once done,
it cannot be undone.
Do not put raw control characters inside a quoted string. That is an extremely
bad practice. Use \x<i>hh</i> notation instead. JSMin will replace control
characters with spaces or linefeeds.
Command Line Options
Optional parameters will be listed at the beginning of the output as comments.
This is a convenient way of replacing copyright messages and other documentation.
Example:
jsmin <jslint.js >jslint.min.js "(c)2001 Douglas Crockford"
Errors
JSMin can produce three error messages to stderr:
Unterminated comment.
Unterminated string constant.
Unterminated regular expression.
It ignores all other errors that may be present in your source program.
Use of JSLint is strongly recommended.
Copyright 2001 Douglas Crockford. All Rights Reserved Wrrrldwide.