HTML Optimization - SpeedWP/mu-plugins GitHub Wiki

Advanced HTML optimization toolkit. Minify, code optimization, search & replace, strip comments and more.

Description

This plugin is a toolkit for advanced HTML code optimization.

The plugin provides in a complete solution for HTML optimization including HTML minification, selective removal of comments and search & replace.

Multiple minifiers and custom minifier

The plugin provides the option to minify HTML code using multiple HTML minifiers including Minify's HTML.php (PHP), HtmlMin (based on PHP 7 symfony/css-selector) and the option to use a custom minifier using a WordPress filter that enables to use any solution, including a Amazon Lambda or Google Cloud function with Node.js based HTML optimization software.

HTML Optimization

HtmlMin configuration

HtmlMin minifier provides many options for tuning the quality of the code minification.

HtmlMin config

Custom minifier

Show custom minifier example
/* Custom HTML minifier */
add_filter('o10n_html_custom_minify', function ($HTML) {

    // apply html optimization
    exec('/node /path/to/optimize-html.js /tmp/html-source.html');
    $minified = file_get_contents('/tmp/output.html');

    // alternative
    $minified = HTMLCompressor::minify($HTML);

    return $minified;

});

Link Optimization

The plugin provides advanced HTML link (<a href>) optimization that includes a MutationObserver innovation to capture and optimize script injected links. This solution enables to add rel=noopener to links to achieve a perfect Google Lighthouse score.

A JSON config filter enables to add, rename or remove attribute and classes, modify href and to apply a CDN with CDN mask.

Link Optimization

Image Optimization

The plugin provides advanced HTML image (<img>) optimization.

A JSON config filter enables to add, rename or remove attributes and classes, modify src and srcset and to apply a CDN with CDN mask.

Image Optimization

Additional features can be requested on the Github forum.

⚠️ **GitHub.com Fallback** ⚠️