mfer’s picture

I have some questions/comments about this (the July 1st version of this):

  1. This diagram shows an AMD loader being sent in a script tag and the rest happens through this loader. Does it download each individual file? Are all the include files it's supposed to load somehow aggregated? I ask because of performance. Browsers download 6 resources from a domain in parallel. When it comes to script loading we want no more than 6 in a group or we can start to have page loading slowdowns. Many Drupal modules including scripts can send us past 6 in a page. On the flip side, aggregating everything into one file has issues as well. It's not as fast and can't take advantage of browser caching as well. That's why the idea of smart bundles (something D7 does a little of) tries to do. So, how will aggregation work or does it not work?
  2. Where do bundles of files come together in this model?
  3. Is there a writeup on why AMD has been chosen? AMD is not something the entire JS community has bought into. Some use build scripts, some use Common JS, some use AMD, and still some use other options. I'm wondering if a case has been put together for this method to sell it compared with the alternatives. I ask because we are looking to make a switch that will be with us for the five years following the release of D8.
  4. What someone wanted to inline their JS? This is a totally valid case. When I first put in the issue for a pluggable loader this is one of the things I was thinking about. Twitter recently switched to inlined JS. It's not unreasonable for some things. How would that case be handled?

Thanks for putting this together. I look forward to talking technical about it.

SebCorbin’s picture

Hello mfer,

  1. The script tag is a config for AMD, where libraries can be associated to their respective file, so a single file might represent multiple libraries:
        baseUrl: "/sites/default/files/js",
        paths: {
            "jquery": "somehash12345.js",
            "underscore": "somehash12345.js"
  2. Bundles would be defined with hook_library_info and alterable through hook_library_alter, basically, an AssetCollection (== alterable bundle) dump would generate a hash, this hash would be then used as a AMD bundle
  3. AMD is just a spec, more and more JS libraries are adopting it ( The optimizer would allow non-compliant scripts to be loaded by wrapping libraries (defined in hook_library_info). I won't do an full argumentation here (sorry), but here's a link to an article where AMD simplicity and adoption is discussed:
  4. An implementation will be available soon

Thanks for the feedback, I'm glad that this case is being taken seriously.