javascriptcssyui-compressor

Concatenating CSS and JS prior to compressing? Tools? Best Practices?


I'm working on a one-page site that is incorporating about a dozen .js files and and maybe a half dozen .css files.

Most of the .js files are jQuery plugins. Aside from a base css file, the CSS files are for the corresponding jQuery plugins.

YUI Compressor seems to be a favorite for compressing CSS and JS files. However, it only compresses individual files.

I'd also like to combine my files and (ideally) end up with one .js and one .css file (both compressed).

Are there any preferred tools out there that allow you to automate the combining of the .js and .css files into one file so it can then be run through YUI compressor?


Solution

  • I ended up stumbling upon this option:

    http://johannburkard.de/blog/programming/javascript/automate-javascript-compression-with-yui-compressor-and-packer.html

    It's a batch file that combines local versions of concatenation, YUI Compressor and Dean Edward's Packer.

    In the end, though, I couldn't get Packer to work locally. It kept corrupting my .js.

    So, I skipped that part and then ran my YUI Compressed code through the online Packer and only saw a 1% further increase in compression, so just omitted the Packer stage.

    In the end, my solution used the above linked instructions with slightly modified batch file:

    type ..\js-in* > jb.js java -jar ..\yui\build\yuicompressor-2.4.2.jar jb.js -o jb-yui.js

    Thanks for all the other (valid) solutions as well. Lots of good info!