Yii allows you to minimize and compress JS. I want to compress the entire JS application and use jQuery hosted by Google. How can I do it?
Yii lets you specify the source for jQuery http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#customizing-asset-bundles
But I already use the bundles key for compressed assets :
'bundles' => require(__DIR__ . '/' . (YII_ENV_PROD ? 'assets-prod.php' : 'assets-dev.php')),
assets-prod.php automatically generated. I tried setting up an asset package during compression using this
assets.php // Asset manager configuration: 'assetManager' => [ 'basePath' => '@webroot/assets', 'baseUrl' => '@web/assets', 'bundles' => [ 'yii\web\JqueryAsset' => [ 'sourcePath' => null, // do not publish the bundle 'js' => [ '//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', ], ], ], ],
But when I ran yii asset assets.php config/assets-prod.php , it did not generate jQuery files at all. This is almost what I wanted, but when I loaded the page, jQuery was completely absent. There was no link to jQuery. He created this in assets-prod.php , which seems wrong
'yii\\web\\JqueryAsset' => [ 'sourcePath' => null, 'js' => [], 'css' => [], 'depends' => [], ],
Ok, so I tried the asset mapping http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#asset-mapping . I put this in web.php
'assetMap' => [ 'jquery.js' => '//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', ],
However, it will still not load jQuery. I returned assets.php and ran yii asset assets.php config/assets-prod.php , but then returned to putting jQuery in one big miniature JS file.