MatthiasMullie\Minify
is a JavaScript and CSS Minifier written in PHP. Usage is straightforward:
use MatthiasMullie\Minify;
$sourcePath = '/path/to/source/css/file.css';
$minifier = new Minify\CSS($sourcePath);
// we can even add another file, they'll then be
// joined in 1 output file
$sourcePath2 = '/path/to/second/source/css/file.css';
$minifier->add($sourcePath2);
// or we can just add plain CSS
$css = 'body { color: #000000; }';
$minifier->add($css);
// save minified file to disk
$minifiedPath = '/path/to/minified/css/file.css';
$minifier->minify($minifiedPath);
// or just output the content
echo $minifier->minify();
The JavaScript version syntax is the same, just swap out the CSS
classes with JS
classes.
Install MatthiasMullie\Minify
using composer:
composer require matthiasmullie/minify
MatthiasMullie\Minify
Source (GitHub) →
Minifier (Demo/Hosted Minify Implementation) →