یکی از راه های مفید در سرعت پردازش سایت و همچنین سئو استفاده از minify و compress کردن فایل های css و javascript هست .
برای این کار روش های متنوعی وجود داره که یکی از مفید ترینشون که من استفاده کردم
استفاده از ویجتی Yii 2 Minify View Component می باشد
برای استفاده از این ماژول ابتدا به وسیله ی composer آن را در اپلیکیشن خود نصب کنید:
composer require "rmrevin/yii2-minify-view:~1.13"
یا قرار دادن کد زیر در فایل composer.json در رووت سایت (در قسمت require)
"rmrevin/yii2-minify-view": "~1.13",
برای اعمال تنظیمات
کد زیر را در components در main.php یا web.php در فولدر config قرار دهید :
'view' => [ 'class' => '\rmrevin\yii\minify\View', 'enableMinify' => !YII_DEBUG, 'concatCss' => true, // concatenate css 'minifyCss' => true, // minificate css 'concatJs' => true, // concatenate js 'minifyJs' => true, // minificate js 'minifyOutput' => true, // minificate result html page 'web_path' => '@web', // path alias to web base 'base_path' => '@webroot', // path alias to web base 'minify_path' => '@webroot/minify', // path alias to save minify result 'js_position' => [ \yii\web\View::POS_END ], // positions of js files to be minified 'force_charset' => 'UTF-8', // charset forcibly assign, otherwise will use all of the files found charset 'expand_imports' => true, // whether to change @import on content 'compress_options' => ['extra' => true], // options for compress 'excludeBundles' => [ \dev\hellowrld\AssetBundle::class, // exclude this bundle from minification ], ]
با اجرای اپلیکیشن در فولدر web فولدری با نام minify ایجاد می شود که برای css ها فایلی جداگانه و برای js ها نیز فایلی جداگانه ایجاد می کند .