PHP code example of asika / minify

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

    

asika / minify example snippets


use Asika\Minifier\MinifierFactory;

$cssMinify = MinifierFactory::create('css');

$jsMinify = MinifierFactory::create('js');

$minify = new \Asika\Minifier\JsMinifier;

// OR

$minify = new \Asika\Minifier\CssMinifier;

use Asika\Minifier\MinifierFactory;

$minify = MinifierFactory::create($type);

$minify->addFile($path); // Add file path
$minify->addContent($path); // Add text content

// Get minify content
$minify->minify();

// To file
$minify->toFile($minifyFile);

$minified = \Asika\Minifier\JsMinifier::process($fileOrContent);

$minified = \Asika\Minifier\CssMinifier::process($fileOrContent);

// Add options for every file
$minify->addFile($path, ['flaggedComments' => false]);

// OR

$minify->addContent($content, ['flaggedComments' => false]);

// OR

\Asika\Minifier\JsMinifier::process($fileOrContent, ['flaggedComments' => false]);

// Use constant as key
$minify->addFile($path, [
    \Asika\Minifier\AbstractMinifier::FLAGGED_COMMENTS => false
]);

// This css in HTML is `{PUBLIC_ROOT}/foo/bar/yoo.css`

$minify->addFile(
    $file,
    [
        'uri_rewrite' => [ // OR \Asika\Minifier\CssMinifier::URI_REWRITE
            'current_dir' => 'foo/bar/yoo.css',
            'doc_root' => $_SERVER['DOCUMENT_ROOT'] // [Optional]
        ]
    ]
);

$css = \Asika\Minifier\CSS\UriRewriter::rewrite(
	$content,
	'foo/bar/yoo.css'
);