I want to compress my JS files automatically with PHP. I tried to find the best plugin for this in many search engines and forms. Everyone suggests the Minify plugin. But this plugin is very large. So, I want a simple and reliable plugin to compress JS files.
Please help me.
I want a plugin like this:
<?PHP
include_once "js_compress.php";
$file = "http://www.example.com/src/page_optimize.js";
$data = file_get_contents($file);
echo js_compress($data);
?>
Use YUI Compressor. I have done similar thing using php.But to do so you have to create a php file with exec command which will run a command of YUI.
So first download their plugin from here : http://developer.yahoo.com/yui/compressor/
Then create a php and put the jar file in the same folder when your php is placed.
But first create a exec string in php like below :
exec(“java -jar compiler.jar –compilation_level SIMPLE_OPTIMIZATIONS –js –js_output_file “);
This will execute the command and compress your js.
For more than 1 files loop the same exec sentence over the input directory and fetch js 1 by 1.
I hope this will help you out.