Skip to content
Advertisement

Minify and join CSS & JS files on linux, server side

In my project, for example, I have this structure:

/public/js/src/ /* many jquery plugins there */
/public/css/src/ /* many css files there, that describe different things */

After changes have been made, I would like to type in command line something like:

root@hostname:/var/www/test/public# ./build

which would generate two files:

/public/css/build.css - all files from /public/css/src/ folder with minified source
/public/js/build.js - all files from /public/js/src folder with minified source

For the moment I am using less css, which is working on node. I would like to have one script that will do everything, for css as for javascript. Could you please advise the best way to “build” dev-source javascript & css files?

Advertisement

Answer

You can use YUI Compressor. I’m sure it’s also available for Linux. It works from the command line. Read here how it works.

Example:

java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js --charset utf-8

I’m sure you can setup a simple Bash script that executes two commands, one for CSS and one for JS by using parameters as input.

Advertisement