2017 © Pedro Peláez
 

library html-min

HTML Compressor and Minifier

image

voku/html-min

HTML Compressor and Minifier

  • Sunday, June 10, 2018
  • by voku
  • Repository
  • 4 Watchers
  • 31 Stars
  • 14,309 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 28 Versions
  • 40 % Grown

The README.md

Build Status Coverage Status Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon, (*1)

:clamp: HtmlMin: HTML Compressor and Minifier for PHP

Description

HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by removing extra whitespaces, comments and other unneeded characters without breaking the content structure. As a result pages become smaller in size and load faster. It will also prepare the HTML for better gzip results, by re-ranging (sort alphabetical) attributes and css-class-names., (*2)

Install via "composer require"

composer require voku/html-min

Quick Start

use voku\helper\HtmlMin;

$html = "
<html>
  \r\n\t
  <body>
    <ul style=''>
      <li style='display: inline;' class='foo'>
        \xc3\xa0
      </li>
      <li class='foo' style='display: inline;'>
        \xc3\xa1
      </li>
    </ul>
  </body>
  \r\n\t
</html>
";
$htmlMin = new HtmlMin();

echo $htmlMin->minify($html); 
// '<html><body>

  • à
  • á
'

Options

use voku\helper\HtmlMin;

$htmlMin = new HtmlMin();

/* 
 * Protected HTML (inline css / inline js / conditional comments) are still protected,
 *    no matter what settings you use.
 */

$htmlMin->doOptimizeViaHtmlDomParser();               // optimize html via "HtmlDomParser()"
$htmlMin->doRemoveComments();                         // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doSumUpWhitespace();                        // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveWhitespaceAroundTags();             // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doOptimizeAttributes();                     // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveHttpPrefixFromAttributes();         // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveHttpsPrefixFromAttributes();        // remove optional "https:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(); // keep "http:"- and "https:"-prefix for all external links 
$htmlMin->doMakeSameDomainsLinksRelative(['example.com']); // make some links relative, by removing the domain from attributes
$htmlMin->doRemoveDefaultAttributes();                // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveDeprecatedAnchorName();             // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromScriptTag();      // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromStyleAndLinkTag(); // remove "type=text/css" from all links and styles
$htmlMin->doRemoveDefaultMediaTypeFromStyleAndLinkTag(); // remove "media="all" from all links and styles
$htmlMin->doRemoveDefaultTypeFromButton();            // remove type="submit" from button tags 
$htmlMin->doRemoveEmptyAttributes();                  // remove some empty attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveValueFromEmptyInput();              // remove 'value=""' from empty <input> (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortCssClassNames();                      // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortHtmlAttributes();                     // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveSpacesBetweenTags();                // remove more (aggressive) spaces in the dom (disabled by default)
$htmlMin->doRemoveOmittedQuotes();                    // remove quotes e.g. class="lall" => class=lall
$htmlMin->doRemoveOmittedHtmlTags();                  // remove ommitted html tags e.g. 

lall, (*3)

=> < p>lall

PS: you can use the "nocompress"-tag to keep the html e.g.: "\n foobar \n", (*4)

Unit Test

1) Composer is a prerequisite for running the tests., (*5)

composer require voku/html-min

2) The tests can be executed by running this command from the root directory:, (*6)

./vendor/bin/phpunit

Support

For support and donations please visit Github | Issues | PayPal | Patreon., (*7)

For status updates and release announcements please visit Releases | Twitter | Patreon., (*8)

For professional support please contact me., (*9)

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerful code style check.
  • Thanks to PHPStan & Psalm for really great Static analysis tools and for discovering bugs in the code!

The Versions

10/06 2018

dev-master

9999999-dev https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

08/05 2018

3.0.3

3.0.3.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

12/02 2018

3.0.2

3.0.2.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

29/12 2017

3.0.1

3.0.1.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

23/12 2017

3.0.0

3.0.0.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

22/12 2017

2.0.4

2.0.4.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

22/12 2017

2.0.3

2.0.3.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

10/12 2017

2.0.2

2.0.2.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

10/12 2017

2.0.1

2.0.1.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

03/12 2017

2.0.0

2.0.0.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

22/09 2017

1.0.9

1.0.9.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

10/09 2017

1.0.8

1.0.8.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

10/09 2017

1.0.7

1.0.7.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

09/09 2017

1.0.6

1.0.6.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

12/05 2017

1.0.5

1.0.5.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

18/03 2017

1.0.4

1.0.4.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

07/12 2016

1.0.3

1.0.3.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

01/12 2016

1.0.2

1.0.2.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

01/12 2016

1.0.1

1.0.1.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

30/11 2016

1.0.0

1.0.0.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

23/10 2016

0.0.7

0.0.7.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

23/10 2016

0.0.6

0.0.6.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

17/10 2016

0.0.4

0.0.4.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

17/10 2016

0.0.5

0.0.5.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

17/10 2016

0.0.3

0.0.3.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

16/10 2016

0.0.2

0.0.2.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

16/10 2016

dev-analysis-X0wel4

dev-analysis-X0wel4 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor

16/10 2016

0.0.1

0.0.1.0 https://github.com/voku/HtmlMin

HTML Compressor and Minifier

  Sources   Download

MIT

The Requires

 

The Development Requires

html minifier compression compress compressor