├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── composer.lock └── src ├── Constants.php ├── Exception ├── ExceptionInterface.php └── FileNotFoundException.php ├── Minifiers ├── Html │ ├── AttributeQuoteMinifier.php │ ├── BooleanAttributeMinifier.php │ ├── CommentMinifier.php │ ├── EmptyAttributeMinifier.php │ ├── JavascriptEventsMinifier.php │ ├── OptionalElementMinifier.php │ ├── RedundantAttributeMinifier.php │ └── WhitespaceMinifier.php └── MinifierInterface.php ├── Minify.php ├── MinifyContext.php ├── Option.php ├── Options.php ├── PlaceholderContainer.php ├── Placeholders ├── CommentPlaceholder.php ├── Php │ └── PhpPlaceholder.php ├── PlaceholderInterface.php └── WhitespacePlaceholder.php ├── Repositories ├── AbstractRepository.php ├── HtmlBooleanAttributeRepository.php ├── OptionalElementsRepository.php └── resources │ ├── HtmlBooleanAttributes.json │ └── OptionalElements.json ├── Statistics ├── ReferencePoint.php ├── Statistics.php └── StatisticsInterface.php └── Util └── Html.php /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guide 2 | **Contributions are always welcome!** 3 | Please rather create a pull request with a fix, or if you can't fix it a pull request with a failing test, than an issue! 4 | 5 | ### Coding style 6 | For pull requests please follow the [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-1](http://www.php-fig.org/psr/psr-1/) standards. 7 | 8 | ### Testing 9 | Always test you're contributions on errors by running the unit test suite with ```vendor/bin/phpunit```. It isn't a goal of the maintainer to achieve 100% code coverage. However every vital and complex part should be tested. 10 | In the case of this package that means that every Minifier and Placeholder strategy must be tested. The regexes in it are rather complex. When bugs are found we've to ensure that the old cases are still working. 11 | Therefore add an unit test to you're pull request if you think it's needed based on the described situation above! 12 | 13 | All unit tests are runned on every pull request by [Travis-CI](https://travis-ci.org/ArjanSchouten/HtmlMinifier). Make sure the tests succeed! Travis is testing on both PHP and HHVM! Both have to succeed! 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Arjan Schouten 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > This package is still in Beta version! Use it with care! 2 | 3 | # HtmlMinifier 4 | 5 | [![Build Status](https://travis-ci.org/ArjanSchouten/HtmlMinifier.svg?branch=master)](https://travis-ci.org/ArjanSchouten/HtmlMinifier) 6 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ArjanSchouten/HtmlMinifier/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ArjanSchouten/HtmlMinifier/?branch=master) 7 | [![Code Coverage](https://scrutinizer-ci.com/g/ArjanSchouten/HtmlMinifier/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ArjanSchouten/HtmlMinifier/?branch=master) 8 | 9 | ## Installation 10 | Let composer do the hard work for us! 11 | ```php 12 | composer require arjanschouten/htmlminifier 13 | ``` 14 | #### Laravel 5.* 15 | A Laravel package based on this minifier can be installed by running: 16 | ```php 17 | composer require arjanschouten/laravelhtmlminifier 18 | ``` 19 | 20 | #### Plain php projects with composer 21 | If you're not using a php framework you can use the minifier by using the code below: 22 | ```php 23 | //include the composer autoloader 24 | require __DIR__ . '/vendor/autoload.php'; 25 | 26 | // create a minify context which will be used through the minification process 27 | $context = new MinifyContext(new PlaceholderContainer()); 28 | // save the html contents in the context 29 | $context->setContents('My html...'); 30 | $minify = new Minify(); 31 | // start the process and give the context with it as parameter 32 | $context = $minify->run($context); 33 | 34 | // $context now contains the minified version 35 | $minifiedContents = $context->getContents(); 36 | 37 | ``` 38 | 39 | ## Options 40 | This minifier have some minification options which are: 41 | 42 | | Minification strategy | Option Name | Enabled by default | 43 | |---------------------------------------------------------------|-------------------------| --------------------| 44 | | Remove redundant whitespaces | whitespaces | yes | 45 | | Remove comments | comments | yes | 46 | | Collapse boolean attributes from checked="checked" to checked | boolean-attributes | yes | 47 | | Remove quotes around html attributes | remove-attributequotes | no | 48 | | Remove optional elements which can be implied by the browser | optional-elements | no | 49 | | Remove defaults such as from ```