Specify domain module should be loaded from

Solved!
Posted in General by Carlos R Wed Nov 25 2015 23:35:07 GMT+0000 (UTC)·5·Viewed 1,456 times

For various reasons my application's javascript sits on a different domain to the Index.html This causes me a problem as when using ocLazyLoad, the request for the module is made from the domain the index.html lives in. eg:- index.html = https://a.domain.com/index.html app.bundle.js = https://b.different-domain.com/js/bundle.js lazyLoadedModule.js = https://a.domain.com/lazyLoadedModule.js (should be same domain as app.bundle.js) Is there any way to specify that the get request for the lazy loaded module should be the same as where app.bundle.js lives?
Olivier Combe
Nov 26, 2015

You should be able to give the full url if you need it, it only requests from the same domain if you give a relative path.


Olivier Combe marked this as solved
Carlos R
Nov 26, 2015

Pardon my completely noobness but could you explain how that may work?

Here's how I'm loading the module...

resolve: {
    load: function ($q, $ocLazyLoad) {
        let deferred = $q.defer();
        require.ensure([], function () {
            let module = require('./path/to/module.js');
            $ocLazyLoad.load({
                name: 'moduleName'
            });
            deferred.resolve(module);
        });

        return deferred.promise;
    }
}

Many thanks.

Olivier Combe
Nov 26, 2015

I'm not very familiar with requirejs, but I'd say that you have to do that :

resolve: {
    load: function ($q, $ocLazyLoad) {
        let deferred = $q.defer();
        require.ensure([], function () {
            let module = require('https://b.different-domain.com/path/to/module.js');
            $ocLazyLoad.load({
                name: 'moduleName'
            });
            deferred.resolve(module);
        });

        return deferred.promise;
    }
}
Carlos R
Nov 26, 2015

I have tried that but to no avail. Appreciate your help nonetheless and thanks for a great plugin.

If I work this out, I'll be sure to post. Similarly if anyone reading knows how to solve this, it would be massively appreciated.

Thanks.

Olivier Combe
Nov 26, 2015

No prob. Since you're using requirejs to load your files, the problems lies within their lib. The js loader from ocLazyLoad is able to load js files from other domains if you give the complete path.

Markdown is allowed