NAME - Output only code (no comments), and reduce white space

SYNOPSIS [-q] [-n] file1.js file2.js ... > file_code.js
  -q means quiet
  -n means no indent

or in a pipeline:

 cat file.js | > file_code.js


This extracts the source code from one or more files.

This utility should work with any source programming language, though it was written for ECMAScript source files.

The opposite utility to this is, which extracts only comments.

We do not try to milk the last byte out of the script. For example, we do not attempt replace all symbol names with shorter ones.

The 'gzip' transfer-encoding in HTTP is an excellent way to further reduce bandwidth requirements when transfering script code to a browser.

By default, we attempt to preserve a certain amount of indenting (with single chars), so that the output script is still somewhat readable.

Because ECMAScript doesn't allow multi-line quoted strings, for simplicity of implementation we currently restrict ourselves to reducing transformations which include a line ending or beginning.


Collapse internal runs of white space, and eliminate internal white space altogether, when semantics are preserved. This will introduce reliance on the input being ECMAScript, and so should be made optional.

Optionally preserve jscript conditional compilation statements hidden in comments: @cc_on @if @else @elif @end


Any simple web search such as reveals many programs that will compress javascript source code, or purports to "obfuscate" it. See for example:

This section contains brief reviews of a semi-random selection of them.


Douglous Crockford has JSMIN: But:

 - it has no indicated license
 - it is written in C (so harder to start using than a perl script)
 - it is rather aggressive about white space (including EOL elimination),
   making the output hard to read
 - it does strive to be correct about quoted strings and regexp literals

Ted Schroyer has

It is a small script written in Perl and licensed under the AFL. However, it is rather careless about protecting the contents of quoted strings (unlike Crockford's, which maintains an internal state machine). It also is not using the '/m' flag when it should.


Mike Hall has the "Crunchinator", see

This is written in javascript, and is intended for use only javascript source. It does deal with strings. It is overly aggressive about combining lines, doing so even when it would break the code (because of implied semi-colons). It does not deal correctly with regexp literals in javascript source code. It is under a restrictive license: .


The DomAPI project has This is a closed-source Windows executable. It claims to follow the same rules as Crunchinator.


Dan Steinman has It is GPL, written in Perl. Does nothing about quoted strings, and in general has little to recommend it.

Salstorm ESC

ESC is at It is written in "JScript", and is under the GPL. It supports variable name subsitution.

Semantic Designs ECMAScriptFormatter

This is a commercial product intended for source code formatting, but it will "obfuscate" as well.



It works on .NET languages including JScript. Will do dead code elimination.


Copyright 2003, Mark D. Anderson,

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.