vmpublishing/slim-html-minify

基于 voku/HtmlMin 并使用 psr-15 的最小化中间件

2.0.2 2019-06-15 08:51 UTC

This package is auto-updated.

Last update: 2024-09-15 20:35:50 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

什么是

尽可能低依赖性的 PSR-15 html 最小化中间件。

存在两个原因

  • christianklisch/slim-minify 产生了错误,因为它只是使用了一些正则表达式。
  • slim 升级到版本 4,因此更改了其中间件接口为 PSR-15 类型

安装

要安装,只需使用 composer require vmpublishing/slim-minify-minify:>=2.0.0

使用

由于这基本上只是 voku/html-min ( https://github.com/voku/HtmlMin ) 的包装,请根据您的喜好进行配置并将实例传递进去,例如

$htmlMin = new HtmlMin();

$htmlMin->doOptimizeViaHtmlDomParser();               // optimize html via "HtmlDomParser()"
$htmlMin->doRemoveComments();                         // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doSumUpWhitespace();                        // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveWhitespaceAroundTags();             // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doOptimizeAttributes();                     // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveHttpPrefixFromAttributes();         // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDefaultAttributes();                // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveDeprecatedAnchorName();             // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromScriptTag();      // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveEmptyAttributes();                  // remove some empty attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveValueFromEmptyInput();              // remove 'value=""' from empty <input> (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortCssClassNames();                      // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortHtmlAttributes();                     // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveSpacesBetweenTags();                // remove more (aggressive) spaces in the dom (disabled by default)

$middleware = new \VM\SlimHtmlMinify\Middlewares\HtmlMinify($htmlMin, true);

# and for slim
$app->add($middleware);

# or the lazy version depending on a container
$app->add(HtmlMinify::class);

# or just add it to specific routes / groups