gulch/minify

Package for minify and optimize HTML code

1.0.2 2018-02-17 15:29 UTC

README

Build Status Coverage Status Scrutinizer Code Quality

gulch/Minify

PHP Package for minify HTML code.

Install

You will need Composer installed.

composer require gulch/minify

How to use

$minifier = gulch\Minify\Minifier::createDefault();
// default optimizations are: whitespaces remove, html comments remove, minification of css and js code
// above code is equivalent to:
// $minifier = new gulch\Minify\Minifier(
//     new gulch\Minify\Processor\WhitespacesRemover,
//     new gulch\Minify\Processor\HtmlCommentsRemover,
//     new gulch\Minify\Processor\InlineCssMinifier,
//     new gulch\Minify\Processor\InlineJavascriptMinifier,
// );
$minified_code = $minifier->process($code);

Advanced optimizations

$minifier = new gulch\Minify\Minifier(
    new gulch\Minify\Processor\WhitespacesRemover,
    new gulch\Minify\Processor\HtmlCommentsRemover,
    new gulch\Minify\Processor\InlineCssMinifier,
    new gulch\Minify\Processor\InlineJavascriptMinifier,
    new gulch\Minify\Processor\QuotesRemover,
    new gulch\Minify\Processor\AttributesSimplifier
);
$minified_code = $minifier->process($code);