Very simple (and very fast) html compression. See benchmark and comparison
- Removing extra whitespaces
- Removing html comments
- Removing trailing slashes from void elements (HTML5)
- Skip
textarea,preandscriptelements - Compresses in microseconds. See benchmark and comparison
- PHP 7.4 or higher
You can install the package via composer:
composer require abordage/html-min<?php
require __DIR__ . '/vendor/autoload.php';
$htmlMin = new Abordage\HtmlMin\HtmlMin();
$result = $htmlMin->minify("<!DOCTYPE html><html> ... </html>");$htmlMin->findDoctypeInDocument(); // default: true
$htmlMin->removeWhitespaceBetweenTags(); // default: true
$htmlMin->removeBlankLinesInScriptElements(); // default: false
$htmlMin->removeTrailingSlashes(); // default: falseIn HTML5, void elements (<link>, <meta>, <img>, <br>, etc.) should not have trailing slashes.
Enable this option to convert XHTML-style tags like <link ... /> to HTML5-style <link ...>.
$htmlMin->removeTrailingSlashes();
$result = $htmlMin->minify('<link rel="stylesheet" href="style.css" />');
// Result: <link rel="stylesheet" href="style.css">See abordage/html-min-benchmark
composer test:allor
composer test:phpunit
composer test:phpstan
composer test:phpcsfor see https://github.com/abordage/html-min/actions/workflows/tests.yml
If you have any feedback, comments or suggestions, please feel free to open an issue within this repository.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
