Login Register

Use of XD loader within the same domain

XD loader is really useful since it allows us to load JS code from different domain. But I am now beginning to think that its value is more than that. I have interest in its asynchronous feature. We might be able to use it for faster code loading since it makes multiple network connections. Also, when we load JS code dynamically, the XD loader does not freeze the browser, that could give a good user experience.

The problem here is that the XD loader seems to be checking if the base script URL is really a cross domain URL or not, and uses the default loader if it is not cross domain. I wanted to use the XD loader within the same domain for the above two purposes. Is there any reason why the XD loader has to be disabled when the URL is not cross domain?

Thanks

In your djConfig, if you set

In your djConfig, if you set djConfig.useXDomain = true and set a djConfig.modulePaths = { "dojo": "http://...." } does that work?

Substitute/add other module prefixes in the modulePaths directory as you need them. Be sure to put one in for every resource you are using (dijit, dojox, your own modules) and make sure they start with "http://" for the paths.

I thought I set it up so that would work, but if that is not, I think it is a bug. More info on how you are configuring your xdomain build would be useful if the above does not work.

I'm afraid not

I'm afraid not. The first thing I tried was djConfig.useXDomain = true. But it didn't work.

I looked into the code (dojo._loadPath) and found that _xdIsXDomainPath() returns false when the url is not cross domain.
The return value(=false) is assigned to currentIsXDomain, then currentIsXDomain is passed to this._loadUri().
I guess this._isXDomain should be used instead of currentIsXDomain.

Ah OK. I think the problem

Ah OK. I think the problem is that we do not know if the corresponding path has xdomain resources created for it (the .xd.js files). I think this test was a crude way of trying to make that determination without needing more info.

If you think having this functionality might be useful, feel free to open an enhancement ticket for the PackageSystem. If you do open it, be sure to reference this forum thread.

Follow up solution

Just a follow up for future reference: it is possible to use xdomain loading from the same domain as the page. The modulePaths just need to be fully qualified URLs. Example (be sure that djConfig is defined before dojo.xd.js is pulled into the page):

djConfig = {
    useXDomain: true,
    modulePaths: {
        "dojo": "http://some.domain.com/dojo10release/dojo",
        "dijit": "http://some.domain.com/dojo10release/dijit",
        "dojox": "http://some.domain.com/dojo10release/dojox" 
    },
    xdWaitSeconds: 10
};

That perfectly solved my

That perfectly solved my problem. Thank you!
I'm glad I can use the XD loader for my app. :-)