ProCache Minify HTML

Contains methods to implement ProCache’s HTML minification features.

Note that documentation in this section uses $min to refer to $procache->minifyHTML, like in the example below.

$html = "<html><body>HTML document markup here</body></html>";
$min = $procache->minifyHTML; // get instance to start using HTML minify
echo "<h1>Original</h1>" . htmlspecialchars($html);
$html = $min->minify($html);
echo "<h1>Minified</h1>" . htmlspecialchars($html);

Default “blocks”

These are block level elements that will have whitespace collapsed around them.

!doctype, address, article, aside, audio, blockquote, body, br, button, canvas, caption, col, colgroup, dd, div, dl, dt, embed, fieldset, figcaption, figure, footer, form, head, header, hgroup, hr, html, li, link, main, map, meta, nav, noscript, object, ol, optgroup, option, output, p, pre, progress, script, section, table, tbody, td, tfoot, th, thead, title, tr, ul, video, h1, h2, h3, h4, h5, h6


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon.

Show $var?     Show args?       Only hookable?    

Common

NameReturnSummary 
$min->convertURLs(string $html, string $rootURL, string $currentURL)
None

Convert URLs from absolute to relative where shorter

 
$min->getOption($name)
null bool

Get the value for an option

 
$min->getOptions()
array

Get the current set options in key => value array

 
$min->minify(string $html)
string

Minify and return the given HTML content

 
$min->minifyInlineCSS(string $html)
int

Minify a CSS string, for inline CSS minification

 
$min->minifyInlineJS(string $html)
int

Minify inline javascript within an HTML document

 
$min->setBlocks($blocks)
$this

Set the block level elements (whitespace removed around these elements)

 
$min->setCSSMinifyFunction(callable $func)
$this

Set the CSS minify callback function

 
$min->setIgnoreTags($tags)
$this

Set the tags that should be ignored

 
$min->setJSMinifyFunction(callable $func)
$this

Set the javascript minify callback function

 
$min->setOption(string $name, bool $value)
$this

Set a minify option

 
$min->setOptions(array $options)
$this

Set multiple options at once in key => value array

 
$min->setRemoveBlankAttrs($attributes)
$this

Attribute names that will be removed when blank

 

Properties

NameReturnSummary 
$min->blankAttrs string array Attributes that may be removed when blank
DEFAULT: ['class', 'dir', 'for', 'id', 'lang', 'style', 'title']
 
$min->blocks string array Tags that we will collapse whitespace around
DEFAULT: see above
 
$min->collapseBooleanAttr bool Collapse boolean attributes, where allowed by HTML5?
DEFAULT: true
 
$min->convertXHTML bool Convert XHTML style "/>" closing tags to HTML ">"?
DEFAULT: true
 
$min->cssMinifyFunction callable Optional callback function to use for CSS minification, see setCSSMinifyFunction() method
DEFAULT: null
 
$min->ignoreTags string array Tags that should be ignored during minification
DEFAULT: ['script', 'style', 'pre', 'textarea', 'svg']
 
$min->jsMinifyFunction callable Optional callback function to use for JS minification, see setJSMinifyFunction() method
DEFAULT: null
 
$min->removeBlankAttr bool Remove blank attributes, where allowed? (configurable, default=true) 
$min->removeComments bool Remove HTML comments?
DEFAULT: true
 
$min->removeUnnecessaryAttr bool Remove unnecessary/redundant attributes from HTML tags?
DEFAULT: true
 
$min->removeUnnecessaryTags bool Remove unnecessary/redundant HTML tags?
DEFAULT: true
 
$min->unquoteAttr bool Remove quotes from attributes, where allowed by HTML5?
DEFAULT: true
 

API reference based on ProcessWire core version 3.0.252