Including the necessary polyfills for every combination of browser support My project uses a Promise polyfill and the fetch polyfill, that I am only including if the browser does not yet support it

// Browser doesn't have Promise
if (!window.Promise) {
  require(['es6-promise'], function(promise) {
    promise.polyfill();
    // Browser doesn't have Promise or fetch
    if (!window.fetch) {
      require(['fetch'], function(fetch) {
        run();
      });

    // Browser doesn't have Promise but does have fetch
    } else {
      run();
    }
  });
// Browser has Promise but doesn't have fetch
} else if (!window.fetch) {
  require(['fetch'], function(fetch) {
    run();
  });
// Browser has Promise and fetch
} else {
  run();
}


This accounts for every permutation of browser support for Promise and fetch, but it seems like a verbose way of doing things. Is there a better to dynamically load these polyfills?
Something tells me that requirejs probably has some features to help with this, but I'm not finding them at the moment.  Your situation is complicated by the fact that you have to run custom code after es6-promise is loaded before fetch is loaded and by the fact that a usual tool for these kinds of problems is promises, but you can't use them here because they may not yet be loaded.  

Here's a solution that is not less overall code, but is more DRY and is more general purpose and could be reused in other projects:

The code to do the custom loading would look like this:

var loaders = [];
if (!window.Promise) {
    loaders.push({modules: 'es6-promise', fn: function(promise) {
        promise.polyfill();
    }});
}
if (!window.fetch) {
    loaders.push({modules: 'fetch'});
}
loadSequential(loaders, run);


And, the implementation of the reusable loadSequential() would look like this:

function loadSequential(list, done) {
    var i = 0;

    // load the next item in the list
    function next() {
        var item;
        if (i &lt; list.length) {
            item = list[i++];
            require(item.modules, function() {
                if (item.fn) {
                    item.fn.apply(this, arguments);
                }
                next();
            });
        } else {
            done();
        }
    }
    // start first iteration
    next();
}




If you can allow fetch to load potentially before promises are available, then you could use the fact that fetch presumably can't exist without promises in a native browser environment (because fetch returns a promise) and could use this shortcut:

if (!window.Promise) {
    // if there's no promise, there can't be a fetch either
    require(['es6-promise', 'fetch'], function(promise) {
        promise.polyfill();
        run();
    });
} else if (!window.fetch) {
    require('fetch', run);
} else {
    run();
}