JSMinHx

JSMinHx is a complete and functional Haxe port of JSMin. You can use it to minify JS files to save some bandwidth.

It is tested on all targets(neko/php/cpp/swf/js).

Download and install

The most easy and proper way is from haxelib:

haxelib install jsmin

Or you can download/checkout the source from github:
http://github.com/andyli/JSMinHx

Usage

From haxelib

haxelib run jsmin inputFile outputFile [level] [comment]

inputFile/outputFile is the relative path with file name to the input/output JS file.

level can be 1 to 3. Value of 3 produces smallest filesize but from my own experience it is very likely to break Haxe generated JS file. Optional, default to 2.

comment will be prepended to the Minified JS file. Optional.

For example:

haxelib run jsmin jquery.js jquery.min.js 2 "//jQuery minified by JSMinHx"

You can integrate it in your release build hxml of your Haxe/JS project:

-main Main
-js release/Main.js
-cmd haxelib run jsmin release/Main.js release/Main.js

Note that the process is not very fast so it is recommended to only minify the JS file for release build.

Using the JSMin class

You can use the JSMin class directly inside your server side Haxe program.

The JSMin class minify the input once it is constructed. You can then get the result from its output property.

var minifiedJS:String = new jsmin.JSMin(jsSource).output;

You can then save the String to a cache directory or whatever you want to do.

Oh, don't forget to add -lib jsmin in your hxml file.

Contribution

You're welcome to improve performance or add utility by forking it from the github repo. Just make a pull request whenever you complete the improvement.

version #8361, modified 2010-03-26 03:02:30 by AndyLi