Cross-domain with requirejs text plugin there is my implementation for cross domain call using the requireJs text plug-in

htaccess file in the template folder of my cross-domain site

Header set Access-Control-Allow-Origin "*"


textremote.js

define(['text','module'],function (text, module) {

    // Load the cross-domain url from the config
    var remoteUrl         = module.config().remoteUrl;

    // Store the current parseName function into a var  
    var originalParseName = text.parseName;

    // Redefine the parseName function      
    text.parseName = function(name) {

        // Use the original parseName 
        var parsed = originalParseName(name);

        // append the cross-domain url to parsed.moduleName
        parsed.moduleName = remoteUrl+parsed.moduleName;

        return parsed;
    }

    // Force CORS to be true 
    text.useXhr = function () {
        return true;
    }
});


In the main config (I remove the non related config)

require.config(
    {
        textremote  : "libs/textremote",

        // this config will be accessible in textremote.js through the module parameters
        config : {
        "textremote" : {
            remoteUrl : "http://www.cross-domain-asset.com/template/"
        }
    },
    }
)


initialization

This ensure that textremote is load first and will ovveride the text.parseUrl and text.useXhr before any usage.

require(['textremote'],function(){
    require(['libs/app'], function(app){
        app.initialize();
    });     
})


Usage example

text!demo.tpl will pass through textremote and text plugin and use 
http://www.cross-domain-asset.com/template/demo.tpl

// Filename: app.js
define([
  'router', // Request router.js
  'backbone',
  'marionette',
  'underscore',
  'text!demo.tpl'
], function(Router,backbone,marionette,_, demoTemplate){
  var initialize = function(){
    // Pass in our Router module and call it's initialize function
    Router.initialize();

   /* ... */

  }

  return {
    initialize: initialize
  };
});


That it, So far this is working well for me. But I would like to improve it or know if better approach exists.

On a side note, I will add code to allow multiple cross-domain usage and caching.
We've had bad experiences in our company for RequireJS. IMO, it has been marketed somewhat wrongly.

RequireJS becoming a script loader - somewhat wrong

True, it does the duties of a script loader. For small apps, this is fine. But when your application begins to grow, as in our case, It's another story. You'll easily end up with a lot of HTTP requests which will choke the static server to the point that you will get script timeout errors. There'll be unnecessary delay in your app due to all the loading and waiting.

RequireJS as a build-tool - better

So what we did was just settle for RequireJS being a build tool. For a dev setup, we allowed it to run as script-loader, a lot of module requests hitting the server. But when it came to deployment, we optimize using the r.js optimizer. This meant grabbing all the needed modules into one machine, let the r.js optimizer run, and end up with one file which you'll use on your page. In addition, we'll be using Almond instead of RequireJS as we don't need the full functionality of RequireJS after it is compiled.

Conclusion

Small scale, it's fine. Large scale, I'd think of something better.