PHP Classes
elePHPant
Icontem

PHP HTML Minify Class: Compress HTML removing unnecessary data

Recommend this page to a friend!
  Info   View files Documentation   View files View files (25)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-05-12 (9 days ago) RSS 2.0 feedStarStarStarStar 73%Total: 295 This week: 13All time: 7,102 This week: 74Up
Version License PHP version Categories
htmlmin 1.0.5MIT/X Consortium ...5.3HTML, PHP 5, Compression
Collaborate with this project Author

HtmlMin - github.com

Description

This class can compress HTML removing unnecessary data.

It can take a given HTML string and perform certain operations to reduce the size of the same document.

Currently it can remove comments, default attributes, anchor names, script charset attributes, the document charset attributes, type from script tags, script mime types, type from style sheet link, empty attributes, http prefix from attributes, value from empty input, whitespace around tags.

It can also sort CSS class names HTML attributes for better gzip compression, and sum up white space.

Innovation Award
PHP Programming Innovation award nominee
November 2016
Number 4
Compressing the HTML of the pages is one way to increase the speed of serving Web pages.

Most packages that perform this task, simply try to remove whitespaces and comments, but this is only one way to reduce the the size of the final HTML.

This package goes father by performing less obvious compression approaches like default removing attributes, changing anchor names to id, removing script and document charset attributes, removing types from script tags and style sheet link, empty attributes, removing http prefix from attributes, and removing values from empty input.

Manuel Lemos
  Performance   Level  
Name: Lars Moelleken <contact>
Classes: 17 packages by
Country: Germany Germany
Age: 29
All time rank: 1659104 in Germany Germany
Week rank: 8 Up1 in Germany Germany Up
Innovation award
Innovation award
Nominee: 7x

Details

Build Status Coverage Status Scrutinizer Code Quality Codacy Badge SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License

HTML Compressor and Minifier

Description

HtmlMin is a fast and very easy to use PHP5.3+ 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.

Install via "composer require"

composer require voku/html-min

Quick Start

use voku\helper\HtmlMin;

require_once 'composer/autoload.php';

$html = '<html>\r\n\t<body>\xc3\xa0</body>\r\n\t</html>';
$htmlMin = new HtmlMin();
echo $htmlMin->minify($html); // '<html><body></body></html>'

Options

$htmlMin = new HtmlMin();

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

$htmlMin->doOptimizeAttributes();                     // optimize html attributes 
$htmlMin->doRemoveComments();                         // remove default HTML comments
$htmlMin->doRemoveDefaultAttributes();                // remove defaults
$htmlMin->doRemoveDeprecatedAnchorName();             // remove deprecated anchor-jump
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute (the browser will use the charset from the HTTP-Header, anyway)
$htmlMin->doRemoveDeprecatedTypeFromScriptTag();      // remove deprecated script-mime-types
$htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); // remove "type=text/css" for css links
$htmlMin->doRemoveEmptyAttributes();                  // remove some empty attributes
$htmlMin->doRemoveHttpPrefixFromAttributes();         // remove optional "http:"-prefix from attributes
$htmlMin->doRemoveValueFromEmptyInput();              // remove 'value=""' from empty <input>
$htmlMin->doRemoveWhitespaceAroundTags();             // remove whitespace around tags
$htmlMin->doSortCssClassNames();                      // sort css-class-names, for better gzip results
$htmlMin->doSortHtmlAttributes();                     // sort html-attributes, for better gzip results
$htmlMin->doSumUpWhitespace();                        // sum-up extra whitespace from the Dom

Unit Test

1) Composer is a prerequisite for running the tests.

composer install voku/html-min

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

./vendor/bin/phpunit

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file circle.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file ISSUE_TEMPLATE.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file PULL_REQUEST_TEMPLATE.md Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagevoku (1 directory)

  Files folder image Files  /  src  /  voku  
File Role Description
Files folder imagehelper (1 file)

  Files folder image Files  /  src  /  voku  /  helper  
File Role Description
  Plain text file HtmlMin.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagefixtures (10 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file HtmlMinTest.php Test Unit test script

  Files folder image Files  /  tests  /  fixtures  
File Role Description
  Accessible without login Plain text file base1.html Data Auxiliary data
  Accessible without login Plain text file base1_result.html Data Auxiliary data
  Accessible without login Plain text file base2.html Data Auxiliary data
  Accessible without login Plain text file base2_result.html Data Auxiliary data
  Accessible without login Plain text file base3.html Data Auxiliary data
  Accessible without login Plain text file base3_result.html Data Auxiliary data
  Accessible without login Plain text file code.html Data Auxiliary data
  Accessible without login Plain text file code_result.html Data Auxiliary data
  Accessible without login Plain text file hlt.html Data Auxiliary data
  Accessible without login Plain text file hlt_result.html Data Auxiliary data

Downloadhtmlmin-2017-05-12.zip 43KB
Downloadhtmlmin-2017-05-12.tar.gz 31KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Simple HTML DOM Download .zip .tar.gz Dom-Parsing Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:295
This week:13
All time:7,102
This week:74Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:-
Tests:91%StarStarStarStarStar
Videos:-
Overall:73%StarStarStarStar
Rank:186