Magento 2 has native feature to JS Minify from the Configuration Setting admin panel.
To Minify JavaScript files in Magento 2 Via admin panel,
Go To Admin panel,
Click Stores -> Settings -> Configuration from the left sidebar.
Select Developer Tab under the Advanced from the left sidebar,
Open the JavaScript Settings section,
Minify Javascript file to Yes,
Click on Save Config.
You can check it programmatically,
<?php namespace Jesadiya\Minify\Model; use Magento\Framework\View\Asset\Minification; class JsMinify { /** * @var Minification */ private $minification; public function __construct( Minification $minification ) { $this->minification = $minification; } /** * Check that js minification is enabled * * @return boolean */ public function isJsMinifyEnabled() { return $this->minification->isEnabled('js'); } }
Use Class, Magento\Framework\View\Asset\Minification to check minify js or not.
Call from the template or any PHP class,
echo $isMinify = $this->isJsMinifyEnabled();
Output:
Boolean