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

mikeytown2’s picture

sun’s picture

Actually, 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).

RobLoach’s picture

Issue tags: +RequireJS

Is 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.

effulgentsia’s picture

Status: Active » Closed (duplicate)

Thanks.

effulgentsia’s picture

Wim Leers’s picture

For RequireJS/AMD specifically, the discussion seems to be continued at #1542344: Use AMD for JS architecture.