For D7, in #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework, we added support for auto-loading new JS files needed by new content returned by an AJAX response. It's basically implemented as a $('head').prepend(SCRIPT_TAGS) (see ajax_render()).
I just came across the RequireJS project. Seems kind of cool, though I haven't played with it yet. But perhaps worth considering for D8. It may help solve potential race conditions that might exist in the approach we're currently using, since I think our current approach adds the new content and runs behaviors without necessarily waiting for the new script to finish loading.
Comments
Comment #1
mikeytown2 CreditAttribution: mikeytown2 commentedalso see
http://drupal.org/project/labjs
http://drupal.org/project/headjs
Comment #3
sunActually, I think we considered RequireJS for D7 at the beginning. But IIRC, we didn't use it, as it was deemed to be included in jQuery core as jQuery.require() (or similar).
Comment #4
RobLoachIs this a duplicate issue to #1033392: Script loader support in core (LABjs etc.)? It seems like the script loader we use is still under debate. Might want to post a link to RequireJS there.
Another jQuery library I just recent saw was jquery-ahm, but we now have ajax.js, which seems to do a lot of the same thing. In any case, we definitely need a JavaScript loader and LabJS and RequireJS both seem like great solutions.
Comment #5
effulgentsia CreditAttribution: effulgentsia commentedThanks.
Comment #6
effulgentsia CreditAttribution: effulgentsia commentedRob Loach, this one's for you: #1149866: Add Backbone.js and Underscore.js to core.
Comment #7
Wim LeersFor RequireJS/AMD specifically, the discussion seems to be continued at #1542344: Use AMD for JS architecture.