Opened 11 years ago

Closed 10 years ago

#12465 closed enhancement (fixed)

Support AMD load from CDN

Reported by: parente Owned by: Rawld Gill
Priority: high Milestone: 1.7
Component: BuildSystem Version: 1.6.0
Keywords: cdn, amd Cc: Adam Peller, Eugene Lazutkin, James Burke
Blocked By: Blocking:


I asked this first on the RequireJS list to get some feedback. Filing it as a feature request for 1.7 or beyond.

I notice that the Dojo 1.6 copy on the Google CDN includes both the Dojo XD built copy of each file plus the Dojo non-XD build of each file. For example:


I also notice the CommonJS main file is also available:

This got me to thinking: could I use RequireJS to load Dojo 1.6 from CDN?

Alas, it doesn't work. The reason seems simple: the non-XD JS files are built copies of the Dojo source meant for use with the old Dojo loader. The AMD define() calls are stripped, for example.

But does it have to be this way? The non-XD JS files are currently useless from the CDN because the old Dojo loader can't access them cross domain. What if the .js files on the CDN were replaced with the Dojo *.js source files with their "AMDness" intact? For instance: - Built for cross-domain Dojo loader - Minified source with AMDness intact

My (naive) impression is that simply minifying the Dojo source files, leaving the AMD define() wrapper intact, and not injecting the dojo.require/provide calls during the build would make any AMD-ready Dojo module loadable cross-domain using an AMD loader. This doesn't break backward compatibility because the *.xd.js files are still there for the old loader and the *.js files weren't doing anything other than taking up space.

Change History (11)

comment:1 Changed 11 years ago by Adam Peller

Cc: Adam Peller added

comment:2 Changed 11 years ago by Eugene Lazutkin

Cc: Eugene Lazutkin added


comment:3 Changed 11 years ago by dante

keep in mind this will NOT work with all dojox modules, as most of them weren't converted to AMD format for 1.6. There was a 1.7 goal, and if we are to ship with "AMD certified" status in 1.7, we should convert all dojox modules, or only ship the AMD wrapped ones.

but all-in-all this is a great idea. Would require minimal transforms to the build: if loader==xdomain, don't unwrap the file. easy enough. testing is hard.

comment:4 Changed 11 years ago by Eugene Lazutkin

I don't know if we can use regular modules for that, or XD ones, or some specially prepared once, but it is worth exploring, and placing on CDN, so loaders can use non-local sources.

comment:5 Changed 11 years ago by parente

James mentioned dijit templates as a potential problem when I first asked this question on the RequireJS mailing list w.r.t. 1.6. The build would have to bake them into the widget JS as strings or wrap the templates in JS modules of their own to support XD loading.

Here's the relevant part of the discussion for reference:

comment:6 Changed 11 years ago by parente

Any update on support for this with the new dojo loader + build system for 1.7?

comment:7 Changed 11 years ago by Adam Peller

Cc: James Burke added
Owner: changed from James Burke to Rawld Gill

comment:8 Changed 11 years ago by Rawld Gill

Milestone: tbd1.7

For 1.7, there is one loader (no more synchronous, xdomain, and debug loader).

The dojo and dijit packages placed on CDNs may be loaded by any AMD-compliant loader. All modules will be expressed in terms of AMD define and all text resources will be interned so there is no need for XHR (which, of course, doesn't work xdomain).

There will be one oddity in the CDN builds: the define applications will include an absolute module identifier do they can be loaded by a <script> element to maintain backcompat.

I'm leaving this ticket open until we have tests in the repo to prove these capabilities.

comment:9 Changed 11 years ago by Rawld Gill

Status: newassigned

comment:10 Changed 11 years ago by Rawld Gill

(In [25387]) added tiny tweaks to get cnd build to include mids, and signal loader of xd legacy mode; refs #12465; !strict

comment:11 Changed 10 years ago by Rawld Gill

Resolution: fixed
Status: assignedclosed

As of v1.7, dojo and dijit are expressed in AMD modules, CDN or otherwise.

Note: See TracTickets for help on using tickets.