Magento 2 has native feature to enable html Minify from the Configuration setting in the admin panel.
Html Minification is not applied in developer mode.
To Minify html in Magento 2 via admin panel,
Go To Admin panel,
Click Stores -> Settings -> Configuration,
Select Advanced -> Developer Tab,
Open Template Settings section,
Html minify set to Yes,
Click on Save Config.
You can Check whether minify of HTML is on via programmatically,
<?php
namespace Jesadiya\HtmlMinify\Model;
use Magento\Framework\View\Asset\ConfigInterface;
class HtmlMinify
{
/**
* @var ConfigInterface
*/
private $htmlMinify;
public function __construct(
ConfigInterface $htmlMinify
) {
$this->htmlMinify = $htmlMinify;
}
/**
* Check that html minification is enabled
*
* @return boolean
*/
public function isHtmlMinifyEnabled()
{
return $this->htmlMinify->isMinifyHtml();
}
}
Call method from the template or PHP class,
echo $isHtmlMinifyEnable = $this->isHtmlMinifyEnabled();
Output:
Boolean
