PHP code example of matthiasmullie / minify

1. Go to this page and download the library: Download matthiasmullie/minify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matthiasmullie / minify example snippets


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();

// just look at the CSS example; it's exactly the same, but with the JS class & JS files :)

use MatthiasMullie\Minify;
$minifier = new Minify\JS($path1, $path2);

$minifier->add($path3);
$minifier->add($js);

$minifier->minify('/target/path.js');

$minifier->gzip('/target/path.js');

$minifier->setMaxImportSize(10);

$extensions = array(
    'gif' => 'data:image/gif',
    'png' => 'data:image/png',
);

$minifier->setImportExtensions($extensions);