Automatically compile and merge files js + css + html in yii2 project. ¶
This solution enables you to dynamically combine js and css files to optimize the html page. This allows you to improve the performance of google page speed.
This tool only works on real sites. On the local projects is not working!
Installation ¶
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist skeeks/yii2-assets-auto-compress "*"
or add
"skeeks/yii2-assets-auto-compress": "*"
How to use ¶
//App config
[
'bootstrap' => ['assetsAutoCompress'],
'components' =>
[
//....
'assetsAutoCompress' =>
[
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
],
//....
]
]
//App config with all options
[
'bootstrap' => ['assetsAutoCompress'],
'components' =>
[
//....
'assetsAutoCompress' =>
[
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled' => true,
'readFileTimeout' => 3, //Time in seconds for reading each asset file
'jsCompress' => true, //Enable minification js in html code
'jsCompressFlaggedComments' => true, //Cut comments during processing js
'cssCompress' => true, //Enable minification css in html code
'cssFileCompile' => true, //Turning association css files
'cssFileRemouteCompile' => false, //Trying to get css files to which the specified path as the remote file, skchat him to her.
'cssFileCompress' => true, //Enable compression and processing before being stored in the css file
'cssFileBottom' => false, //Moving down the page css files
'cssFileBottomLoadOnJs' => false, //Transfer css file down the page and uploading them using js
'jsFileCompile' => true, //Turning association js files
'jsFileRemouteCompile' => false, //Trying to get a js files to which the specified path as the remote file, skchat him to her.
'jsFileCompress' => true, //Enable compression and processing js before saving a file
'jsFileCompressFlaggedComments' => true, //Cut comments during processing js
'noIncludeJsFilesOnPjax' => true, //Do not connect the js files when all pjax requests
'htmlFormatter' => [
//Enable compression html
'class' => 'skeeks\yii2\assetsAuto\formatters\html\TylerHtmlCompressor',
'extra' => false, //use more compact algorithm
'noComments' => true, //cut all the html comments
'maxNumberRows' => 50000, //The maximum number of rows that the formatter runs on
//or
'class' => 'skeeks\yii2\assetsAuto\formatters\html\MrclayHtmlCompressor',
//or any other your handler implements skeeks\yii2\assetsAuto\IFormatter interface
//or false
],
],
//....
]
]
Links ¶
Demo (view source code) ¶
SkeekS CMS (Yii2) — fast, simple, effective!
skeeks.com | cms.skeeks.com
Cache
Will this extension create a cache of the minified resources?
Or will It make the compression on every request?
Thanks!
Cache
Yes, the result is cached on some hash. Everything works quickly and optimally for each request.
Jsonu
At my server its always pick the css and js from the old cache. Recent changes will not reflect on website. Even after deleting the all cache from the frontend/web/assets/* directory. so please help i need to show recent changes on website.
Cache
Configure Asset yii2 a manager with the option in your project
... 'components' => [ ... 'assetManager' => [ 'appendTimestamp' => true, ...
Example: https://github.com/skeeks-cms/cms/blob/master/config/main.php#L102
SSL certificate problem: unable to get local issuer certificate
On my remote server it gives me below error with details
Level 1 level Detail LEVEL_ERROR Category skeeks\yii2\assetsAuto\AssetsAutoCompressComponent Log Time 2016-07-31 13:41 Prefix Message SSL certificate problem: unable to get local issuer certificate
Excellent Extension: but I have faced two issues
Thanks for the amazing extension.
I have faced two issues:
1- when the Javascript contains "@TODO" as a comment it breaks the whole compressed script file
2- If you have special script/CSS for certain browsers (Conditional using ALT) then the Compression will add them always. Suggestion to create multiple files one for the general scripts/CSS and multiple for the conditional CSS/script
Cdn Stuff
I am including the cdn css and js files in my assets. for local directory files the js and css are compressed fine. but it is not working with the cdn files. i want to compress cdn files and make a compress so how it is possible with this.
Cdn Stuff
19960
@silverspark
It is not yet implemented, but planned.
https://github.com/skeeks-semenov/yii2-assets-auto-compress/issues/3
https://www.yiiframework.com/extension/skeeks/yii2-assets-auto-compress — actual version
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.