pfaciana/tiny-html-minifier
Composer 安装命令:
composer require pfaciana/tiny-html-minifier
包简介
Minify HTML in PHP with just a single class
README 文档
README
In short
- A HTML minifier in PHP.
- It's really really fast.
- Only 1 file is required.
- Almost no regular expressions.
- Almost no options.
Details - What the minifier does
- Remove HTML comments.
- Remove slash in self closing elements.
/>becomes>. - Remove
type="text/css"andtype="text/javascript"instyleandscripttags. - Minimize elements within
<head></head>. It will not keep any whitespace (except insidescript). - Minimize elements within
<body></body>but keep spaces between tags to preserve inline data (optional). - Minimize inline SVG files (which are a bunch of XML tags).
- Minimize Custom Elements. They look like this:
<my-element>My content</my-element>. - Skip
code,pre,scriptandtextareafrom being minified.
Install & usage
Composer
composer require pfaciana/tiny-html-minifier
PHP
<?php require __DIR__ . '/vendor/autoload.php'; use Minifier\TinyMinify; echo TinyMinify::html($html);
Before / after
Before
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0" /> <link href="http://example.com/style.css" rel="stylesheet" /> <link rel="icon" href="http://example.com/favicon.png" /> <title>Tiny Html Minifier</title> </head> <body class="body"> <div class="main-wrap"> <main> <textarea> Some text with newlines and some spaces </textarea> <div class="test"> <p>This text</p> <p>should not</p> <p>wrap on multiple lines</p> </div> </main> </div> <script> console.log('Script tags are not minified'); console.log('This is inside a script tag'); </script></body> </html>
After
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><link href="http://example.com/style.css" rel="stylesheet"><link rel="icon" href="http://example.com/favicon.png"><title>Tiny Html Minifier</title></head> <body class="body"><div class="main-wrap"> <main> <textarea> Some text with newlines and some spaces </textarea> <div class="test"> <p>This text</p> <p>should not</p> <p>wrap on multiple lines</p> </div> </main> </div> <script> console.log('Script tags are not minified'); console.log('This is inside a script tag'); </script></body></html>
Options
<?php require __DIR__ . '/vendor/autoload.php'; use Minifier\TinyMinify; echo TinyMinify::html($html, $options = [ 'collapse_whitespace' => false, 'disable_comments' => false, ]);
collapse_whitespace
Not collapsed
Spaces are preserved (except for most elements within <head></head>). It's good when using the elements inline. This is the default.
<ul><li> <a href="#"> My link </a></li><li> <a href="#"> My link </a></li> </ul>
Collapsed
Spaces are collapsed. The text inside the element is still untouched. Set this value to true and you will save a few extra bytes.
<ul><li><a href="#">My link</a></li><li><a href="#">My link</a></li></ul>
Requirements
- PHP7+
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
Donate
If you want to make a donation, you can do that by sending any amount https://www.paypal.me/DevoneraAB
Credits
pfaciana/tiny-html-minifier 适用场景与选型建议
pfaciana/tiny-html-minifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 103.64k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2020 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html」 「minify」 「minifier」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pfaciana/tiny-html-minifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pfaciana/tiny-html-minifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pfaciana/tiny-html-minifier 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
HTMLMin Is A Simple HTML Minifier For Laravel
Caching and compression for Twig assets (JavaScript and CSS).
CSS & JavaScript minifier for Silverstripe
A package for pack css and javascript files
统计信息
- 总下载量: 103.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 21
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-27