I'd like a tool that will:
a) roll a bunch of separate js files into one
b) minify my js
Any ideas?
I'd like a tool that will:
a) roll a bunch of separate js files into one
b) minify my js
Any ideas?
From an answer I made a bit ago...
The YUI Compressor is a tool I use, it compresses both JS and CSS well, and it is written in Java (so you can work it into a build process via ant). Someone's even made an online version of it.
It doesn't handle rolling the files together, but that's not really difficult - you can do that yourself by simply concatenating the files. For example, on *nix you could rollup and compress with a simple shell script:
# Target all your js files somehow, this is just an example
cat *.js > rollup.js
# Compress with YUI Compressor
java -jar yuicompressor-x.y.z.jar -o rollup-min.js rollup.js
jQuery has two build systems. One based on make and on based on ant. With either of two is very easy to do what you want.
ant based build is more portable (at least on windows)
Dojo's custom builder is pretty awesome. You can use it to create one or several javascript files, via a simple configuration file. I use it in conjunction with scons to build my site.
super naive build file based on ant. This build.xml file is assuming that you've js files in directory "js":
<?xml version="1.0" encoding="UTF-8"?>
<project default="minify" basedir=".">
<target name="prepare">
<mkdir dir="dist"/>
</target>
<target name="clean">
<delete dir="dist"/>
</target>
<target name="concat" depends="prepare">
<concat destfile="dist/mylib-debug.js" fixlastline="true">
<fileset dir="js" includes="*.js" />
</concat>
</target>
<target name="minify" depends="concat">
<!--
-- invoke http://inconspicuous.org/projects/jsmin/jsmin.java
-- or invoke YUICompressor.jar on dist/mylib-debug.js
-->
</target>
</project>
YUICompressor is definitely a great way to go (as suggested earlier). A more robust and complete solution with Ant tie in is discussed on the creator of YUICompressor's blog: http://www.julienlecomte.net/blog/2007/09/16/. He deals with JS, CSS, and caching issues.
This looks pretty interesting to me. http://mojo.codehaus.org/javascript-maven-tools/javascript-maven-plugin/index.html
A Django-specific solution is http://code.google.com/p/django-compress/, which can combine scripts and minify the results using jsmin. It can also combine stylesheets and minify the result using CSSTidy.