skeeks-semenov / yii2-assets-auto-compress Goto Github PK
View Code? Open in Web Editor NEWAutomatic compilation of js + css + html
Home Page: https://skeeks.com/
License: BSD 3-Clause "New" or "Revised" License
Automatic compilation of js + css + html
Home Page: https://skeeks.com/
License: BSD 3-Clause "New" or "Revised" License
Я думаю, надо создать MAP файл.
if app set theme after render yii display
Invalid Parameter – yii\base\InvalidParamException
The view file does not exist: /home/wwwroot/com.yii/backend/views/site/index.php
Here I have mark false for all still its compressing all css and js
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled' => false,
'readFileTimeout' => 3, //Time in seconds for reading each asset file
'jsCompress' => false, //Enable minification js in html code
'jsCompressFlaggedComments' => false, //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' => false, //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' => false, //Enable compression and processing js before saving a file
'jsFileCompressFlaggedComments' => false, //Cut comments during processing js
'htmlCompress' => true, //Enable compression html
'htmlCompressOptions' => //options for compressing output result
[
'extra' => false, //use more compact algorithm
'no-comments' => true //cut all the html comments
],
How to turn off compression here ?
меняет width: calc(100% - 20px) на width:calc(100%-20px);
(убирает пробелы) что недопустимо ;(
Очень частая ситуация... система зависимостей загрузки бандлов в Yii, в зависимости от ситуации может менять очередность загрузки, из-за этого создаются новые дубликаты файлов... в реалности стоит добавить сортировку перед генерацией хеша, что бы получался всегда один и тот же результат
ЭТО ОПЦИОНАЛЬНО, так как в некоторых случаях это может давать нехороший результат!!!
when compress css files and js files,you foreach them and then getContents with Url::to( \Yii::getAlias('@web'.$fileCode), true)
It may course a bug
for example:
if my asset $fileCode is “/admin/assets/a466841a/index.css”
and my web (use \Yii::getAlias('@web')) is "/admin"
then this result will be "/admin/admin/assets/a466841a/index.css"
now, you see, you can't find this file!
I think you can replace "Url::to( \Yii::getAlias('@web'.$fileCode), true)" with "Url::to($fileCode), true)"
Sometimes asset manager paths are customized in main configuration. Due this extension have fixed routes it will not match the real assets folder.
There are some css and js files in the project that should not compress. I can't seem to find an option to exclude these files. Is there a way to do this?
Hi,
if cssFileCompile
is enabled, each file configured in the asset gets minified (using Minify_CSS::minify
) at:
https://github.com/skeeks-semenov/yii2-assets-auto-compress/blob/master/src/AssetsAutoCompressComponent.php#L534
If cssFileCompress
is enabled, it will get minified a few lines later again (using CssMin::minify
):
https://github.com/skeeks-semenov/yii2-assets-auto-compress/blob/master/src/AssetsAutoCompressComponent.php#L568
I think complie should only concatenate the asset files into a single CSS file and it should compress this single CSS file only once and only if cssFileCompress
is enabled.
What do you think?
Andreas
When I activate your autocompress then my fileupload is no longer working. EVEN when I set all the settings to FALSE.. I still get the following error
Any suggestions
VM936:1 Uncaught TypeError: jQuery(...).fileupload is not a function
at eval (eval at globalEval (jquery-2.2.4.min.js:2), <anonymous>:1:54)
at eval (<anonymous>)
at Function.globalEval (jquery-2.2.4.min.js:2)
at ua (
I got following error on remoter server which is implemented with ssl:
SSL certificate problem: unable to get local issuer certificate
I have checked the source of the page, it has minify the html but not concatenated the css and js files
what will be the cause of this issue
Getting error like :
RuntimeException
Unclosed regex pattern at position: 266184
in C:\xampp\htdocs\freemelroseheights_protected\vendor\tedivm\jshrink\src\JShrink\Minifier.php at line 525
in C:\xampp\htdocs\freemelroseheights_protected\vendor\tedivm\jshrink\src\JShrink\Minifier.php at line 240 – JShrink\Minifier::saveRegex()
in C:\xampp\htdocs\freemelroseheights_protected\vendor\tedivm\jshrink\src\JShrink\Minifier.php at line 144 – JShrink\Minifier::loop()
.
.
.
This is a really good extension but i have an issue:
Whenever i set jsFileCompile to true and load some AJAX my js events doesn't' fire. E.G. Load page
Click button this fires:
$(document).on("click", ".showModalButton", function () {
After ajax has loaded i click the button again and the event doesn't fire
I also have an onSubmit event that should fire on a form that was loaded via ajax this event is not fired.
All the functions work fine without the combining file open.
Hope you can help!
When a css file is missing your code never ends
my configuration is as follow:
'bootstrap'=>['assetsAutoCompress'],
'components' => [
'assetsAutoCompress' =>
[
'class'=>'skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled'=> true,
'jsCompress'=> true,
'cssFileCompile' => true,
'jsFileCompile' => true,
],]
I can see it is compiling all assets(jqueryAsset, YiiAsset, AppAsset,..) and bringing one js compressed file and one css compressed file. But the css compressed is empty(nothing inside) and the content of the js compressed file is :
;;;;;;;;;;;;;;;;;;;;;;;;;
which is making even the call of $.() to prompt error in consolog:
(index):899 Uncaught ReferenceError: jQuery is not defined(anonymous function) @ (index):899
Ive checked your main component and found setWebroot section thinking this is where I could hack it in my config/bootstrap.php making an alias for webroot to no avail.
here is my apache conf
"bty" is like my backend
on frontend everything compresses fine
any help?
Alias /bty "/Server/BTY/web/bty"
<Directory "/Server/BTY/web/frontend">
<IfModule mod_php5.c>
php_value include_path "/Server/BTY/app"
php_admin_flag engine on
</IfModule>
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Directory>
<Directory "/Server/BTY/web/bty">
<IfModule mod_php5.c>
php_value include_path "/Server/BTY/app"
php_admin_flag engine on
</IfModule>
<IfModule mod_rewrite.c>
RewriteBase /bty/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
</Directory>
here is my bty/config/bootstrap.php
@bty is my main app folder
Yii::setAlias('web', '@BTY/web/bty/');
Yii::setAlias('webroot', '/');
{return/^(?:(?:https?|file)\:)?\/\//.test(e)}
becomes:
{return/^(?:(?:https?|file)\:)?\/\}
When it's compressed. As you can see, not just the end of the regex, but the following function call, are removed. Based on the fact that the regex ends with '//', I assumed it might be something to do with automatically removing comments. But I added:
'jsFileCompressFlaggedComments' => FALSE
To my config, and the error persisted. So I'm not sure what might be causing the problem.
Hi,
this extension is awesome.
To speed things up, it would be great to skip files ending with .min.css or .min.js from running again through e.g. CssMin::minify.
Best thing would be to have this configurable per AssetBundle, but I'm not sure if this will be possible. On the other hand a regex (configurable in the assetsAutoCompress configuration array) could do the job.
What do you think?
Kind regards from Austria
Andreas
I'm getting this error, am using the exact settings in your example too.
Setting unknown property: skeeks\yii2\assetsAuto\formatters\html\MrclayHtmlCompressor::extra
I'm on php 8.0.8 and yii2 2.0.42.1
Error in PHP 7.4.0
yii\base\ErrorException: implode(): Passing glue string after array is deprecated. Swap the parameters in /vendor/skeeks/yii2-assets-auto-compress/src/AssetsAutoCompressComponent.php:380
$content = implode($resultContent, ";\n");
need
$content = implode( ";\n", $resultContent);
Hi, I am not able to run codeception tests when the module is active because calls to $I->amOnRoute(...)
or $I->amOnPage(...)
breaks with:
[yii\base\InvalidConfigException] Unable to determine the request URI.
It is possible to leave the CSS in the tag <style>
, instead of the file?
Error PageSpeed Insights
None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.
Source css file contained
@media screen and (min-width: 992px) {
.header-navigation li {
display: inline-block;
padding-top: 3px;
padding-right: 3px;
padding-left: 3px;
text-align: center
}
.header-navigation li a {
text-transform: none
}
@media screen and (-webkit-min-device-pixel-ratio: 0) {
/* Safari and Chrome */
.header-navigation li a {
letter-spacing: 1px
}
}
/* Only Chrome */
@media all and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: .001dpcm) {
.header-navigation li a {
letter-spacing: 2px
}
}
}
@media screen and (min-width: 1024px) {
...
which became (beautified)
@media screen and (min-width: 992px) {
.header-navigation li {
display: inline-block;
padding-top: 3px;
padding-right: 3px;
padding-left: 3px;
text-align: center
}
.header-navigation li a {
text-transform: none
}
@media screen and (-webkit-min-device-pixel-ratio: 0) {
.header-navigation li a {
letter-spacing: 1px
}
}
@media all and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: .001dpcm) {
.header-navigation li a {
letter-spacing: 2px
}
}
@media screen and (min-width: 1024px) {
...
Note that final closing curly bracket on "min-width: 992px" section is missing
GET http://localhost/advv/ net::ERR_CONNECTION_REFUSED
Why don't you add minify to your composer file?
Hello,
I have faced this problem with JS compression.
Even though all JS files are compressed, the original JS files get appended before it.
So I have done some modifications in code and it worked.
Changes are done in AssetAutoCompressComponent.php in _processingJsFiles() function
The new code is at line 362
if (file_exists($rootUrl))
{
$resultFiles = [];
foreach ($files as $fileCode => $fileTag)
{
if (Url::isRelative($fileCode))
{
} else
{
if (!$this->jsFileRemouteCompile)
{
$resultFiles[$fileCode] = $fileTag;
}
}
}
$publicUrl = $publicUrl . "?v=" . filemtime($rootUrl);
$resultFiles[$publicUrl] = Html::jsFile($publicUrl, $this->jsOptions);
return $resultFiles;
}
Kindly make changes in original repo.
Part of the CDN address, after compression, dependency order error
ParseError: syntax error, unexpected end of file, expecting function (T_FUNCTION) in vendor\skeeks\yii2-assets-auto-compress\AssetsAutoCompressComponent.php:646
i update my css files in current assets , but not updated my css codes in the plugin created css file.
how i can update this file and clear the cache??
Hi! when I'm trying to use this extention on a real site,not local! my css file is empty and my javascript files compact to a file with this content
`<title>301 Moved Permanently</title>
I don't understand why it 's in this way!
Hello,
I am using Skeeks-CKEditor in code and Yii2-assets-auto-compress for compressing assets.
When I am using it, the dynamically generated assets path is not coming correctly.
CKEditor code:
<?= skeeks\yii2\ckeditor\CKEditorWidget::widget([
'name' => 'content',
'id' => 'content',
'options' => ['rows' => 6],
'preset' => CKEditorPresets::FULL,
'clientOptions' =>
[
'height' => 120,
],
]); ?>
and Asset-auto-compress code is:
'assetsAutoCompress' => [
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled' => true,
'readFileTimeout' => 10,
'jsCompress' => true,
'jsCompressFlaggedComments' => true,
'cssCompress' => true,
'cssFileCompile' => true,
'cssFileRemouteCompile' => true,
'cssFileCompress' => true,
'cssFileBottom' => false,
'cssFileBottomLoadOnJs' => false,
'jsFileCompile' => true,
'jsFileRemouteCompile' => true,
'jsFileCompress' => true,
'jsFileCompressFlaggedComments' => true,
'htmlCompress' => false,
'noIncludeJsFilesOnPjax' => true,
'htmlCompressOptions' =>
[
'extra' => false,
'no-comments' => true
],
],
Both the plugins are developed by you. So just help me out to resolve this.
Hi,
I'm on a point where my combined css grows above 278kB which causes issues in IE9, as this stupid browser cannot handle stylesheets bigger than this limit (see: http://stackoverflow.com/a/23241583).
Luckily this limit is per file basis, so I though the solution will be "Grouping Asset Bundles" (http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#grouping-asset-bundles).
As far as I understand the process of building the grouped assets is either manually (unsing grunt or similary component) or by using the AssetControllers Console command.
Are you familary with Grouping Assets? Do you think this could also be done using your great yii2-asset-auto-compress extension? This would make things pretty easy (for me ;-)
Kind regards and thank you for your help
Andreas
У меня есть некий универсальный ассет на все фронтенд страницы... Допустим так
app\assets\FrontendAsset::register($this);
Но на одной из страниц я хочу добавить еще один внешний ассет гуглокарт... (сделал без ассетов)
$this->registerJsFile('https://maps.googleapis.com/maps/api/js?language=ru', ['depends' => 'yii\web\JqueryAsset']);
Там где нет гуглокарт создается комбинированный файл с хешем №1
Там где есть гуглокарты создается тот же самый комбинированный файл с хешем №2
Получается тупняк!!!
Решение кроется здесь:
$fileName = md5( implode(array_keys($files)) . $this->getSettingsHash()) . '.js';
$publicUrl = \Yii::getAlias('@web/assets/js-compress/' . $fileName);
Я думаю правильно не создавать хешь для файлов http:// https:// и //, исключить их из генерации хеша, тогда все будет гуд...
До исправления проблемы судя по всему должен работать костыль с document.write
Автор... еще раз спасибо за отличное дополнение... очень ждем фикса - он очень простой...
my configuration is as follow:
'bootstrap'=>['assetsAutoCompress'],
'components' => [
'assetsAutoCompress' =>
[
'class'=>'skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled'=> true,
'jsCompress'=> true,
'cssFileCompile' => true,
'jsFileCompile' => true,
],]
But when I run the website I am getting the error :
Class skeeks\yii2\assetsAuto\AssetsAutoCompressComponent does not exist
Where I am wrong?
Заходя на страницы, на которых я не был - грузятся по 15 - 20 сек., что бы склеить стили со скриптами, а это очень долго. Так и должно быть или я что не правильно делаю?
In my AssetBundle I can set the "async" attribute for javascript tag adding:
public $jsOptions = [
'async' => 'async',
];
But when the javascript is compressed, the async attribute disappear. Is it possible to keep it (or to set it somewhere else?).
Thanks
'condition' => 'lte IE 8',
yii\bootstrap\Modal
Modals don't work after compression
Hi,
When I applied this into advanced template for frontend it is not wokring. Browser loading continuously (like server goes into infinite loop)
Please Help
how to compress when use renderAjax ?
Having Gzip compression for JS files saves a lot of bandwidth for clients and improves page speed for webmasters
I'm trying to pass
'cssOptions' => ['media' => 'none', 'onload' => 'media=\'all\'']
for the compressed css file but i'm unable to do that
so i would get
<link href="/marelin/public_html/assets/css-compress/01f2afb3b58a1c5381de41bcb1d365b8.css?v=1487767908" rel="stylesheet" media="none" onload="media='all'">
instead of
<link href="/marelin/public_html/assets/css-compress/01f2afb3b58a1c5381de41bcb1d365b8.css?v=1487767908" rel="stylesheet">
Hello,
Is there any particular reason, when we are generating new compressed files, that we don't clear the previous versions?
Thanks.
I found that because the compressed resources are suffixed by a '?v=' parameter that has the file creation time, effectively resource caching is defeated.
Why is this? The name of the file is already made of the MD5 of the file content, so why is there another parameter which is not really used anyway? I assume you tried to defeat the resource caching if the file was modified, but in that case, the MD5 would differ anyway. By adding an URL parameter, nothing gets cached at all.
If I am correct, it would suffice to just remove the code lines where the '?v=' is added.
Hi:
Weird behaviour. I have this config:
'class' => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
'enabled' => true,
'readFileTimeout' => 3000, //Time in seconds for reading each asset file
'cssCompress' => true, //Enable minification css in html code
'cssFileCompile' => true, //Turning association css files
'cssFileRemouteCompile' => true, //Trying to get css files to which the specified path as the remote file, skchat him to her.
'cssFileCompress' => false, //Enable compression and processing before being stored in the css file
'cssFileBottom' => true, //Moving down the page css files
'cssFileBottomLoadOnJs' => true, //Transfer css file down the page and uploading them using js
'jsCompress' => true, //Enable minification js in html code
'jsCompressFlaggedComments' => true, //Cut comments during processing js
'jsFileCompile' => true, //Turning association js files
'jsFileRemouteCompile' => true, //Trying to get a js files to which the specified path as the remote file, skchat him to her.
'jsFileCompress' => false, //Enable compression and processing js before saving a file
'jsFileCompressFlaggedComments' => false, //Cut comments during processing js
'htmlCompress' => true, //Enable compression html
'htmlCompressOptions' => //options for compressing output result
[
'extra' => true, //use more compact algorithm
'no-comments' => true, //cut all the html comments
],
So, it's just working JUST AFTER deleting the assets folder ... if there's something already created in the folder, it will not minified.
I have tried with other configuration, even turning everything off and just turn on the jsCompress. Same behaviour
Thank you for any help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.