Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fine grained URL control

jrburke edited this page Aug 8, 2012 · 4 revisions

Sometimes you may want to control the URLs used to fetch modules in a way that cannot be done using the normal baseUrl, paths, map and/or urlArgs config.

You can override requirejs.load() to do this work. Save off a reference to the original requirejs.load implementation, and then modify the URL as you want before delegating to the original implementation:

<script src="require.js"></script>
<script>
(function () {
  var load = requirejs.load;
  requirejs.load = function (context, moduleId, url) {
    //modify url here, then call original load
    return load(context, moduleId, url);
  };

  //Now load code.
  require(['main']);
}());
</script>

NOTE 1: Loader plugin resources do not go through requirejs.load(), so this approach will not work if you want to catch those resources and associated URLs.

NOTE 2: requirejs.load() is a semi-private API meaning it can change at any time. Traditionally it has been fairly stable, but by modifying it, you are taking on the responsibility of updating your modification in later requirejs releases. There are no guarantees it will stay the same in the future.

Clone this wiki locally
Morty Proxy This is a proxified and sanitized view of the page, visit original site.