doncadavona / html_minifier
A PHP package to minify HTMLs, CSSs and Javascripts.
dev-master / 1.0.x-dev
2017-06-26 06:12 UTC
Requires
- php: ~5.6|~7.0
Requires (Dev)
- phpunit/phpunit: ~4.0||~5.0||~6.0
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2025-05-01 20:00:29 UTC
README
HTML Minifier
A PHP package to minify HTMLs, Javascripts and CSSs. Supports PSR-4 Autoloader.
Install
Via Composer
$ composer require doncadavona/html_minifier
Usage
use DonCadavona\HtmlMinifier\HtmlMinifier; // Sample HTML string $html = ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> html { padding-top: 20px; } body { margin: 0px; } </style> </head> <body> <h1>Hello World</h1> <script> // This is single-line a comment. /* This is a multi-line comment. */ /** * This is a doc block comment. */ </script> </body> </html> '; // Minify the HTML echo HtmlMinifier::minify($html); // <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style type="text/css"> html { padding-top: 20px; } body { margin: 0px; } </style></head><body><h1>Hello World</h1><script></script></body></html> // Minify the HTML and remove JavaScripts and CSSs: echo HtmlMinifier::minify($html, true, true); // <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><h1>Hello World</h1></body></html>
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email dcadavona@gmail.com
instead of using the issue tracker.
Credits
- Oleg Gheorghita for his yii2-htmlcompress package.
License
The MIT License (MIT). Please see License File for more information.