百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

HtmlMin

> 前端框架
开源

:clamp: HtmlMin: 通过 PHP 进行 HTML 压缩和最小化

182 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

:clamp: HtmlMin: 通过 PHP 进行 HTML 压缩和最小化

:clamp: HtmlMin: HTML Compressor and Minifier for PHP

Description

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.

Install via "composer require"

bash
composer require voku/html-min

Quick Start

php
use voku\helper\HtmlMin;

$html = "

  \r\n\t
  
    

      

        \xc3\xa0
      

      

        \xc3\xa1
      

    

  
  \r\n\t

";
$htmlMin = new HtmlMin();

echo $htmlMin->minify($html); 
// '

 à 
 á 
'

Options

…

Current optional tag support from the WHATWG HTML syntax rules:

  • ``: start tag may be omitted when the first child is not a comment; end tag may be omitted when the element is not immediately followed by a comment.
  • ``: start tag may be omitted when the element is empty or starts with an element; end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.
  • ``: start tag may be omitted when the element is empty or starts with something other than ASCII whitespace / a comment / 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.
  • ``: the end tag may be omitted before another option, optgroup, or hr, or at the end of the parent.
  • ``: the end tag may be omitted before another optgroup or hr, or at the end of the parent.
  • ``: the start tag may be omitted when the first child is 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.
  • ``: the end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.
  • ``: the end tag may be omitted before tbody or tfoot.
  • ``: the start tag may be omitted when the first child is 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.
  • ``: the end tag may be omitted 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"

Unit Test

  1. Composer is a prerequisite for running the tests.
composer require voku/html-min
  1. The tests can be executed by running this command from the root directory:
bash
./vendor/bin/phpunit

Support

For 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.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerful code style check.
  • Thanks to PHPStan & Psalm for really great Static analysis tools and for discovering bugs in the code!

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPhacktoberfesthtmlhtmlcompressorhtmlmin

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架