This extension provides ability to process and combine local assets, thus relieving the developer from having to strictly control what assets used in project and how they organized.
This also makes the page load faster by reducing the page size and reducing the loading of additional files.
Extension combines all included .js files in a page, minifies it and include result to the page as a single .js file. This generated file is cached.
All inline javascript is minified and stays in the same place on the page. You can set option to cache this generated parts to prevent multiple generation of the same code parts.
Like javascript processing, all .css files are minified and included in the page as a single .css file. This generated file is cached.
All inline CSS is combined and minified. Like javascript processing, you can set option to cache this generated code parts.
Extension also provides ability to minify whole HTML on page. There are two generation strategies used in component:
Add "nabu/yii2-compressr": ">=0.0.4"
to composer.json
or run
composer require --prefer-dist nabu/yii2-compressr ">=0.0.4"
[
'bootstrap' => ['compressr'],
'components' => [
...
'compressr' =>
[
'class' => 'nabu\yii2\compressr\Compressr',
'enabled' => true, // enables component. possible use: 'enabled' => YII_ENV_PROD
'compressJs' => true, // compress and minify whole javascript on page
'jsCutComments' => true, // cut comments in javascript code
'jsCacheInlineParts' => true, // cache inline code parts. need the cache to be configured and enabled
'compressCss' => true, // compress and minify whole css on page
'cssCacheInlineParts' => true, // cache inline code parts. need the cache to be configured and enabled
'compressHtml' => true, // compress html
// possible options: HtmlCompressStrategy::MRCLAY or HtmlCompressStrategy::TYLER
'htmlCompressStrategy' => \nabu\yii2\compressr\html\HtmlCompressStrategy::MRCLAY,
],
]
]
First time heavy page called:
Subsequent times with caching: