Answer the question
In order to leave comments, you need to log in
Compressing CSS and JS resources in Yii2 by group?
Good afternoon, the question is the following:
I compress resources according to the instructions, such a config:
/**
* Configuration file for the "yii asset" console command.
*/
// In the console environment, some path aliases may not exist. Please define these:
Yii::setAlias('@webroot', realpath(__DIR__ . '/../web'));
Yii::setAlias('@web', '/');
return [
// Adjust command/callback for JavaScript files compressing:
'jsCompressor' => 'java -jar optimize/closure-compiler-v20210505.jar --js {from} --js_output_file {to}',
// Adjust command/callback for CSS files compressing:
'cssCompressor' => 'java -jar optimize/yuicompressor.jar --type css {from} -o {to}',
// Whether to delete asset source after compression:
'deleteSource' => true,
// The list of asset bundles to compress:
'bundles' => [
'yii\web\YiiAsset',
/*другие бандлы*/
],
// Asset bundle for compression output:
'targets' => [
'app\\assets\\CompressedAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/main-{hash}.js',
'css' => 'css/main-{hash}.css',
],
],
// Asset manager configuration:
'assetManager' => [
'basePath' => '@webroot/assets',
'baseUrl' => '@web/assets',
],
];
'targets' => [
'app\\assets\\MainAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/main-{hash}.js',
'css' => 'css/main-{hash}.css',
'depends' => [
'yii\web\YiiAsset',
],
],
'app\\assets\\CalcAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/main-{hash}.js',
'css' => 'css/main-{hash}.css',
'depends' => [
'app\assets\AppAsset'
],
],
'app\\assets\\ContactAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/main-{hash}.js',
'css' => 'css/main-{hash}.css',
'depends' => [
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset',
],
],
],
Answer the question
In order to leave comments, you need to log in
I figured out the Bundle that is cut on each page (Yii, Jqeury, etc.) must be specified without
dependencies
'targets' => [
'app\\assets\\CompressCalcAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/calc-{hash}.js',
'css' => 'css/calc-{hash}.css',
'depends' => [
'app\assets\CalcAsset',
],
],
'app\\assets\\ContactAsset' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/contact-{hash}.js',
'css' => 'css/contact-{hash}.css',
'depends' => [
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset',
],
],
'app\\assets\\MainAsset' => [ //критический бандл
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'baseUrl' => '@web',
'js' => 'js/main-{hash}.js',
'css' => 'css/main-{hash}.css',
'depends' => [],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question