Use minified version of JqueryAsset, BootstrapAsset (and all default assets)

You are viewing revision #1 of this wiki article.
This is the latest version of this article.

By default, Yii 2.0 chooses to use the non-minified version of Jquery and Bootstrap files (CSS and JS). However, there's a simple way to indicate Yii to use the minified version.

In your config file set this up.

'components' => [ // Check that you are inside "components" section
		'assetManager' => [
			'class' => 'yii\web\AssetManager',
			'bundles' => [
		                'yii\web\JqueryAsset' => [
		                    'js' => [
		                        YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js'
		                    ]
		                ],
		                'yii\bootstrap\BootstrapAsset' => [
		                    'css' => [
		                        YII_ENV_DEV ? 'css/bootstrap.css' : 		'css/bootstrap.min.css',
		                    ]
		                ],
		                'yii\bootstrap\BootstrapPluginAsset' => [
		                    'js' => [
		                        YII_ENV_DEV ? 'js/bootstrap.js' : 'js/bootstrap.min.js',
		                    ]
		                ]
			],
		],
		// ... Some other components
	],


This way in Development environment you'll have the unminified version, but in Production Yii will use the minified file.

This works for all the assets which don't use the minified version by default.