It’s pretty easy to minimize scriptS with Yuicompressor. Unfortunately, this process is totally slow when executing the JAR with exec in php.
Example (PHP):
// start with basic command
$cmd = 'java -Xmx32m -jar /bin/yuicompressor-2.4.8pre.jar -o \'/var/www/myscript.min.js\' \'/var/www/myscript.min.temp.js\'';
// execute the command
exec($cmd . ' 2>&1', $ok);
The execution time for ~20 files takes up to 30 seconds ! on a Quad Core Server with 8GB Ram.
Does anybody know a faster solution, to minimize a bunch of scripts ?
The execution time mainly depends of the file size(s).
Let’s take a try with Google Closure Compiler.
It is also a good idea to caching the result in a file or use some extensions (APC, Memcached) with the combination of client-side caching headers. If you checking the last modification time with filemtime() you will know to need minify or not.
I often use separate caching by files, to prevent minification of a large content, then creating an MD5 checksum by the whole and if it is modified since the last request, then save the new checksum and print out the content, else just using:
By this way, it is a very few calculations by each requests also in dev state. I’m using ExtJS 4 for my current project wich is 1.2 MB large at raw and a lot of project-codes without any problem and under 1s response time.