Yii cookbook(russian) says, that assets hepls to prevent resource dublication, when it used by many components.
I dont understand how it helps to prevent resource dublication because when publishing assets full path to recource is used.
For example i wont to create few extensions(widgets). Each extension use the same script. Right way is to put js to widget_dir/views/assets and publish it. But when i will use both this extensions, script will be dublicated, beause we have 2 copies of this script: widget1_dir/views/assets/some_script.js and widget2_dir/views/assets/some_script.js
Then widget will be not universal and when i download some widget to protected/exensions/some_widget, i will need to care about placing js to corresponding directory. And many people use different directories to store their scripts. If somebody store his js in webApp/js or webApp/protected/js, it will ugly to create another dir for some scripts. Changing path to js in widget sources is bad practice, placing path to js to config is ugly to.
We need desigion, that let to use extesions from the box and don’t care about path to commonly used scripts and script dublication.
I guess that is a question of chouce: if you want an extension that will work out of the box, it should incorporate all needed script.
If I understand good, you want create 2 independent extension that will both work out of the box but which share some js script?
Yes, exacly. Extensions must incorporate all needed js and i need to avoid script dublication.
Standart Yii functionality can help to solve this problem?
What is most beautiful & universal way to do that?
It must be transparent for developers and html makeup
I think what you are trying to say and it is a good point -if it is what I think it is:
— if a widget has a jquery.fancybox.js and another has fancybox.js, both of them will register a duplicate of the same file.
Is that right?
But it could be great if there was an automated way (through the code) to publish external js libraries to the web/js/source folder and packages.php updated with new repository.
The extensions from jquery plugin are growing very fast in the community, if the problem you expose is actually true, then I think the way widgets or extensions created should review its conventions.
I’m quite sure there was some discussion about this about 1-2 years ago. Unfortunately i can’t find that topic now. If i remember well there where concerns about dependency issues, like mismatch of versions etc. It’s not easy at all to find a generic solution for this (and that’s what you need if you want to publish something to the community).
The idea of gii analyzing the files in the application is also really good. We could create some ‘js plugins and/or js libraries’ patterns for analyzing and search duplicated files, create a CClientScript configuration option (scriptMap) for config/main.php file and display also the differences between the files. Also timestamps, differences reports.
I believe that the duplicated files could be solved (not in the way we were talking about that i think could be really cool) is to check which libraries the extensions are using and create a scriptMap manually.
Could be very, very good that a tool could analyze our site (as tri suggested) on the folders we specify and check the scripts used and build a scriptMap array in order to avoid duplicates.
mmm… or even build a component that is preloaded and analyzes, stores results in a cached source and is the scriptMap to be used afterwards…