https://github.com/abordage/html-min
HtmlMin is very simple (and very fast) PHP package for minification HTML
https://github.com/abordage/html-min
html-compress html-minification html-minifier html-minify
Last synced: 4 months ago
JSON representation
HtmlMin is very simple (and very fast) PHP package for minification HTML
- Host: GitHub
- URL: https://github.com/abordage/html-min
- Owner: abordage
- License: mit
- Created: 2022-06-12T12:18:40.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-23T08:03:43.000Z (over 1 year ago)
- Last Synced: 2025-10-23T14:02:57.846Z (8 months ago)
- Topics: html-compress, html-minification, html-minifier, html-minify
- Language: PHP
- Homepage:
- Size: 68.4 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# HtmlMin: PHP package for HTML minification
Very simple (and very fast) html compression. See [benchmark and comparison](https://github.com/abordage/html-min-benchmark)
## Features
- Removing extra whitespaces
- Removing html comments
- Removing trailing slashes from void elements (HTML5)
- Skip `textarea`, `pre` and `script` elements
- Compresses in microseconds. See benchmark and comparison
## Requirements
- PHP 7.4 or higher
## Installation
You can install the package via composer:
```bash
composer require abordage/html-min
```
## Quick start
```php
minify(" ... ");
```
## Options
```php
$htmlMin->findDoctypeInDocument(); // default: true
$htmlMin->removeWhitespaceBetweenTags(); // default: true
$htmlMin->removeBlankLinesInScriptElements(); // default: false
$htmlMin->removeTrailingSlashes(); // default: false
```
### Remove trailing slashes
In HTML5, void elements (``, ``, `
`, `
`, etc.) should not have trailing slashes.
Enable this option to convert XHTML-style tags like `` to HTML5-style ``.
```php
$htmlMin->removeTrailingSlashes();
$result = $htmlMin->minify('');
// Result:
```
## Benchmark
See [abordage/html-min-benchmark](https://github.com/abordage/html-min-benchmark)
## Testing
```bash
composer test:all
```
or
```bash
composer test:phpunit
composer test:phpstan
composer test:phpcsf
```
or see https://github.com/abordage/html-min/actions/workflows/tests.yml
## Feedback
If you have any feedback, comments or suggestions, please feel free to open an issue within this repository.
## Contributing
Please see [CONTRIBUTING](https://github.com/abordage/.github/blob/master/CONTRIBUTING.md) for details.
## Credits
- [Pavel Bychko](https://github.com/abordage)
- [All Contributors](https://github.com/abordage/html-min/graphs/contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.