PHP code example of premento / minify

1. Go to this page and download the library: Download premento/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/ */

    

premento / minify example snippets


use Premento\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 Premento\Minify;

$minifier = new Minify\HTML($sourcePath);

// save minified file to disk
$minifier->minify($targetPath);

// or just output the content
echo $minifier->minify();

use Premento\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);

$minifier->setAggressiveWhitespace();

$minifier->setMinifyInlineAssets(false);

// our nav uses `li { display: inline }`, but our `span`s are all display:block
$minifier->setBlockElements(array('div', 'p', 'ul', 'span'));

$minifier->setVerbatimElements(array('pre', 'textarea', 'code-sample'));
html
<!-- source -->
<p>Some <strong>bold</strong> <em>and italic</em> text.</p>

<!-- default: renders as "Some bold and italic text." -->
<p>Some <strong>bold</strong> <em>and italic</em> text.</p>

<!-- aggressive: renders as "Some boldand italic text." -->
<p>Some <strong>bold</strong><em>and italic</em> text.</p>