I have a php application that accepts submitted javascript code and makes use of Google’s Closure Compiler to minimize it.
The php script uses exec() command to invoke the compiler in the following manner:
exec('java -jar compiler.jar --js file.js', $output);
The problem with this approach is the time it takes to the java engine to load each time the compiler.jar and execute the compression, about 3 seconds to minimize a simple code like:
alert ( "hello" );
I presume that this is due to the time it takes to load the java engine and the jar file, plus the time it takes to process the javascript code.
My question is, what are the options here to improve the speed?
One of the ideas that go thru my mind is perhaps converting the compiler.jar into a servlet that receives a post with the code and the options, then returns the result, via http or a socket, and run it in Tomcat. But as I’m not familiar with java code, that approach may be complex, and yet I don’t know if it would greatly improve the speed.
Please let me know how would you approach it, thanks!
Don’t bother to create a java runtime server, others have already done that
Have a look at Nailgun
You can have a look at GroovyServ, too, as it’s java compatible.