Can anyone point me to a place where I can find more info about how assets feature works? Or provide me with such information in general? If I’m not mistaken this topic is covered in Yii documentation in short and with not enough details.
I would need some basic info:
[*]How to control when and which files yii puts there?
[*]Can I delete these files when moving application from developement to production server?
[*]Can I delete contents of this folder from time to time, if it gets to big in size?
[*]What is the difference between assets and protected/runtime folders? If I understand yii documentation properly both are being used for the same reason - to store files being used temporairly, only in runtime.
And so on.
The problem that troubles me much is that yii is getting rather space-hunger when using this folder / feature. For example I found out in very basic application build on base of yii demo app that I have three copies of jQuery put into three different folders, each occupying 745 kB. And THE only moment jQuery was used in my app was a ONE TIME run of gii for generate one example model. If I’m not mistaken I also noticed some demo apps unpacking jQuery to assets folder where jQuery was not used at all - i.e gii was disabled as by default and absolutly no jQuery related code was used in the page.
Three copies of jQuery that is 2,18 MB of additional webspace which is being wasted in my opinion. If we go this way and app can get really really big after being used for months and for many users! I’m generally not get used to app extracting any extra files into some folders where I have rather no control on which files, where and when are put. I’m an old-school web-developer where knowing exactly what file is where and for what reason is the base for maitaining webapp good health.
Can’t understnad why it isn’t solved the way with fixed folder names - i.e. jQuery is being extracted to a fixed folder name under assets and yii core only checks if that folder name exits, if not - recreate it. What is the reason to have three or more exactly the same (byte-by-byte check) copies of jQuery under assets folder? Especially if you take under consideration that if jQuery gets updated while yii not, one still will have to manually ‘override’ this feature and add new version of jQuery on it’s own.
Thanks in advance for any explanations in this topic!
If Yii calculates assets basing on hash, then how to explain that after using an app for a month I have three exact copies of jQuery UI in assets folder of which two were created in the same time (see folder dates)? See attachment:
Can someone explain me what is the reason in such non-sense space waste? Isn’t that a bug?
No, it is not a matter of size or space, of course. In these days - as you say - when you can have 750 GB hosting for as much as ten bucks / month. But I’m trying to figure out - with a little help of more experienced Yii developers - if the fact that I have two different copies of jQuery generated exactly in the same moment (the same date and time up to particular minute) is trully a feature of Yii or bug?
Here goes about whole picture. Three directories and 3 MB for a week or two of running test-drive mode by one user with as much as ten request pers minute. If we go this way, then what about a year or half of running in production mode, being used by thousands of people and generating millions of requests per second?
Thanks for the link below. But still - I’m not trying to find out how to stop this behaviour but to make myself sure that it isn’t truly a bug (as it look for me right now) but fully controlled and code-optimised feature - i.e. it have to go this way, even if it looks like a bug.
No, you certainly not! This is what I’m talking about and this is what worries me the most!
Right now I’m developing only a small application with ONE additional widget - menu (rest of assets folder contents comes as garbage after different menu system tested and are not recreated after remove) - and with extensive use of jQuery.
Even if I use only jQuery and one widget I have three exact copies of jQuery after one month of using this app alone. What about, if it will be used months by thousands? What about if I introduce more widgets?
Did you maybe update your Yii version? Check the CAssetManager::hash() method. This is where the hashed directory name for a file to publish is generated. It only depends on the source file (or directory) name + the Yii version. If none of both changes, there will be no new folders in assets.
I WAS informed (earlier in this topic) that assets hash depends only on file or directory name and Yii version. Therefore there must be a bug in yii about core (‘jquery’) lib itself. Because I didn’t neither upgraded Yii (still on 1.1.4) nor I changed folder name, as we are talking about jQuery, which is a part of Yii and therefore user has nothing to do with its source folder name.
Yes, I can confirm, observations that I have (about doubling, tripling or more of assets folder) are only related to core JS scripts that ships with Yii. I haven’t observed generating more then one assets folder for scripts and other assets that are user-related.
I’ve been using app I’m talking about for around 1 month and since that time I cleaned assets folder at least five times. I did not looked to assets after each request, but I noticed that jQuery asset is being republished after each assets folder clean, once in two copies once in three.
I don’t have time to check each file, but taking in account that each of this copy has exactly the same size (745 145 bytes) and the same file/folder structure, then I assume that yes - these folders has exactly the same content.
Today I discovered another, as I think weird, thing. If assets folder name is being generated only basing on folder name (internal, not changing as we are talking about jQuery that ships with Yii) and only on Yii version then how it is possible that name of that assets folder has changed, if Yii hasn’t been upgraded by me? Once it was 9d8be0eb, another time 67…something, now it is 418d6bd7. Size still exactly the same - 745 145 bytes. Isn’t that something weird?
No, I’m not afraid of reading source codes! Actually, reading Yii codes is a really interesting adventure as they are written (at least in my opinion) in so clear and professional that one can learn a lot out of it.
I did some researches in source code after Qiang’s replies to the bug I reported and found possible answer to my problem. See below post.
After doing some dig in Yii source code I think I found out solution. It seems that I misunderstood the idea of what path means here. For all the time I assumed that hash is being generated upon relative path to internal jQuery asset up upon Yii main dir. But it turned out that it must be an absolute path. My Yii version hasn’t been updated (though contents of Yii folder hasn’t changed in anyway) but I recently updated my server package from XAMPP Lite to XAMPP full and therefore it’s (and Yii’s) absolute path has changed from x:\xampplite to x:\xampp (under Windows).
It happened on 2010-11-11 11:42 and this probably caused regeneration of assets folder.
It still concerns be (if you take a look at screenshot I provided) why there has been two exact copies of jQuery asset generated exactly on the same date, hour and minute on 2010-11-10 15:04 as I don’t recall any changes to Yii or folder structure by that date. But this will be hard to explain and I believe it will be a good idea to end this discussion (again).
As I wrote in bug report, if I find something new in this topic I’ll write here or in bug report, but looking on the Yii source code it seems that no matter what I’ll find I will be 99,99% cause of my changes made in for example folder structure. It seems that this is truly not a bug, so I was wrong assuming this.