How to minify css and js in Yii2

Minification is the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser - e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so also you can compress your css and js file into one minified resource so it took less time response in server.



yii2-assets-auto-compressPlease add the dependency in your composer file:

"skeeks/yii2-assets-auto-compress": "*"

In your main.php (frontend->config->main.php)


//App config
[
'bootstrap' => ['assetsAutoCompress'],
'components' =>
[
'assetsAutoCompress' =>
[
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled' => true, // false if you don't want to minify the assets
'jsCompress' => true,
'cssFileCompile' => true,
'jsFileCompile' => true,
],
]
]

Now you can can your compile assets on page.

No comments:

Post a Comment

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...

Popular