:clamp: HtmlMin: 通过 PHP 进行 HTML 压缩和最小化
HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by removing extra whitespaces, comments and other unneeded characters without breaking the content structure. As a result pages become smaller in size and load faster. It will also prepare the HTML for better gzip results, by re-ranging (sort alphabetical) attributes and css-class-names.
composer require voku/html-minuse voku\helper\HtmlMin;
$html = "
\r\n\t
\xc3\xa0
\xc3\xa1
\r\n\t
";
$htmlMin = new HtmlMin();
echo $htmlMin->minify($html);
// '
à
á
'…Current optional tag support from the WHATWG HTML syntax rules:
meta / noscript / link / script / style / template; end tag may be omitted when it is not immediately followed by a comment. : end tag may be omitted before address, article, aside, blockquote, details, dialog, div, dl, fieldset, figcaption, figure, footer, form, h1-h6, header, hgroup, hr, main, menu, nav, ol, p, pre, search, section, table, or ul, or at the end of the parent when the parent is not a, audio, del, ins, map, noscript, video, or an autonomous custom element. , , , , , , , and : the end tag may be omitted in the standard adjacent-sibling / end-of-parent cases from the spec.option, optgroup, or hr, or at the end of the parent.optgroup or hr, or at the end of the parent.col and the previous omitted-tag rule does not block it; the end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.tbody or tfoot.tr and the previous omitted-tag rule does not block it; the end tag may be omitted before tbody / tfoot or at the end of the parent.Start tags are never omitted when the element has attributes.
PS: you can use the "nocompress"-tag to keep the html e.g.: "\n foobar \n"
composer require voku/html-min./vendor/bin/phpunitFor support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
暂无开放 Issues,或尚未同步最近议题。