An open API service indexing awesome lists of open source software.

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

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)


HtmlMin


Packagist Version


GitHub Tests Status


GitHub Code Style Status


PHP Version Support


License

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