You can use PHP-JS-CSS-Minifier , it is a PHP library that compresses javascript and css files in real time and saves it to a project folder.
Based on the Javascript Minifier site API. Just include the codes as in the example:
include_once("minifier.php");
$js = array(
"js/application.js" => "js/application.min.js",
"js/main.js" => "js/main.min.js"
);
$css = array(
"css/application.css" => "css/application.min.css",
"css/main.css" => "css/main.min.css"
);
minifyJS($js);
minifyCSS($css);
I tested with the jQuery plugin through their url https://code.jquery.com/jquery-3.2.1.js
and worked as expected:
include_once("minifier.php");
$js = array(
"https://code.jquery.com/jquery-3.2.1.js" => "js/jquery-3.2.1.min.js"
);
minifyJS($js);
The disadvantage is that since the compression is done in real time, the request becomes slow and ends up not being an advantage to place directly in the body of the page of your site, since every time it will perform this compression. One output would be to insert a if
before starting the compression and compare the date of the two files to check if your script is up to date.