There are many times when it is necessary to do extra work to avoid the same script from being included twice. For example, if you have two polls, the first snippet call should register the necessary js library, the second should not. As it is, it is necessary to add a parameter such as &disable_js_libs to many snippets to handle this. It is a small inconvenience, but those ’gotchas’ add unnecessary complexity for beginning users.
Another example is a page that uses MooTools works fine, until you log into the manager and QuickEdit includes MooTools again and breaks the page.
It would be nice if these conflicts were handled automatically. I suggest adding two or three optional arguments to regClientScript and regClientStartupScript. They would look something like this:
string regClientScript($src,$identifier='',$version='',$mode=HIGHEST_VERSION)
So if one script called
regClientScript('assets/someplace/jquery.js','jQuery','1.3.1');
and another script called
regClientScript('assets/someotherplace/jquery.js','jQuery','1.3.2');
only the second script would be registered, since it has a higher version number.
For snippets that can be included multiple times in the same page, just using
regClientStartupScript('assets/snippets/mysnipname/mysnipname.js','mysnipname');
Would only register the script the first time, not multiple times. That would be very nice.
One more feature:
regClientScript('assets/someplace/lib.js','EXTJS','2.2.1');
regClientStatupScript('assets/someotherplace/lib.js','EXTJS','2.1');
would register the 2.2.1 version as a STARTUP script (if any of the calls are for a startup script, the selected version will be put in the head of the document).
What do you think of this idea? I don’t think it would be very hard to write the code for it.