Jake Shakesworth
Jake Shakesworth

Reputation: 3555

Have RequireJS load a specific library based on browser

Our project is using a library that has two different versions depending on whether its running in IE or not-IE. We are currently using RequireJS to load libraries -- is there a way to configure RequireJS to load the library based on the detected browser? I've looked at the documentation but I can't find any examples that fit my use case.

Upvotes: 0

Views: 36

Answers (1)

Damian Dziaduch
Damian Dziaduch

Reputation: 2127

What about using https://requirejs.org/docs/api.html#config-map ?

You can check the browser via user agent and then map the module to different one:

function isIe() {
  // return true if is Internet Explorer
}

requirejs.config({
    map: {
        '*': {
            'foo': isIe() ? 'foo-for-ie' : 'foo'
        }
    }
});

Upvotes: 1

Related Questions