Developer resources
Welcome to /dev, our resource area for Web developers and netheads.
All tools and information on this site are provided "as is", and carry absolutely no warranty whatsoever!
Zen Solutions accepts no responsibility for any effects, defects, failures or inaccuracies.
That said, if you do find any problems, please contact us and give us your feedback.
FYI, your IP address is 18.226.187.210
Online Javascript Minifier
This page provides an online Javascript code minifier. It is implemented - appropriately - entirely in Javascript, and so no code you enter here is ever sent to the Zen Solutions server. This code is based on the original design in C by Douglas Crockford. It was converted to Javascript by Franck Marcia and others.
If you would like to read Douglas Crockford's description of how JSmin works, click here. Please also visit Douglas Crockford's Javascript website for a huge range of useful resources.
Comments
You can add any comments here (e.g. a copyright or version note); this text will be appended to the start of the minified output.
Code
Write, or copy & paste, your Javascript code here
Minimal: original algorithm but keep linefeeds if single
Conservative: original algorithm
Agressive: remove more linefeed than the original algorithm but can be regressive
Output
Stats
The JavaScript Minifier
Douglas Crockford, 2003
JSMin is a filter which 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.
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. For examnple :
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. 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;}
Note that lines have been split for clarity
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 \xhh notation instead. JSMin will replace control characters with spaces or linefeeds.
Use parentheses with confusing sequences of + or -. For example, minification changes
a + ++b
into
a+++b
which is interpreted as
a++ + b
which is wrong. You can avoid this by using parens:
a + (++b)
JSLint checks for all of these problems. It is suggested that JSLint be used before using JSMin.