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.
Great Tip, Thank You!!!
Your tip also lead me to solving one of my frustrations, in that most of the time I need jQuery to be loaded before the body of the page. To do so, I modified your jQuery entry as follows:
'yii\web\JqueryAsset' => [ 'jsOptions' => ['position' => 1], 'js' => [ YII_ENV_DEV ? 'jquery.js' : 'jquery.min.js' ] ],
PR?
This should go into the Yii2 core. Have you considered creating a pull request?
Thanks for the tip!
Super!
jQuery UI:
'yii\jui\JuiAsset' => [ 'css' => [YII_DEBUG ? 'themes/smoothness/jquery-ui.css' : 'themes/smoothness/jquery-ui.min.css'], 'js' => [YII_DEBUG ? 'jquery-ui.js' : 'jquery-ui.min.js'], ],
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.