Search code examples
dojodoh

How to locally test cross-domain builds?


Using the dojo toolkit, what is the proper way of locally testing code that will be executed as cross-domain, without making the actual build?

As it appears, there are three possible options (each, with their own drawbacks):

  1. Using local (non xd) XMLHttpRequest dojo.require
    • This option does not really test the xd behavior, since it dojo.require[s] the js synchronously via XHR.
  2. djConfig.debugAtAllCosts = true;
    • Although this option does load the required code asynchronously (via the 'script' tag), it also pulls the code in via XHR, parses the dojo.require[s] inside that, and pulls them in. This (using the loader_debug), again, is not what the loader_xd is doing. More info on this topic in a different question.
  3. Creating a cross-domain build
    • This approach requires a build, which is not possible in the environment which I'm running the code in (We're using our own on-the-fly build process, which includes only the js that is necessary for a particular page. This process is not suitable for development).

Thus, my question: is there a way to use the loader_xd, which does not require an xd build (which adds the xd prefix / suffix to every file)?

The 2nd way (using the debugAtAllCosts) also makes me question the motivation for pre-parsing the dojo.require[s]. If the loader_xd will not (or rather can not) pre-parse, why is the method that was created for testing/debugging doing so?


Solution

  • I don't think there's any way to do XD loading without building and deploying it. Your analysis of the various options seems about right.

    debugAtAllCosts is there specifically to solve a debugging problem, where most browsers, until recently, could not do anything intelligent with code brought in through eval. Still today, Firefox will report exception in the console as appearing at the eval site (bootstrap.js) with a line number offset from the eval, rather than from the actual eval buffer, and normally that eval buffer is anonymous. Firebug was the first debugger to jump through some hoops to enhance the debugging experience and permitted special metadata that Dojo's loader injects between the XHR and the eval to determine a filepath to the source. Webkit/Safari have recently implemented this also. I believe debugAtAllCosts pre-dates the XD loader.