karolinski
karolinski

Reputation: 577

Loading external script with RequireJS

I want to attach this script : http://findify-assets-2bveeb6u8ag.netdna-ssl.com/search/prod/beatmed.com.min.js with RequireJS, but It destroys other scripts from require.

My js config:

var config = {
    paths: {
        "findify": "//findify-assets-2bveeb6u8ag.netdna-ssl.com/search/prod/beatmed.com.min",
        "test": "////maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min"
    },
}
require.config(config);

In HTML:

<script type="text/javascript">
  require(['findify']);
</script>

I have problem with the findify script, the "test" loads without errors in console.

Console Errors:

enter image description here

enter image description here

This script loads also other files for example: beatmed.com.min.js

Upvotes: 0

Views: 1068

Answers (1)

Legends
Legends

Reputation: 22712

If you take a look at the findify script below, you can see that it overrides the requirejs implementation require and can therefore not find its exec function anymore. So findify is loaded correctly, but then requirejs is gone!

Findify-script excerpt

require = function a(b, c, d) {
    function e(g, h) {
        if (!c[g]) {
            if (!b[g]) {
                var i = "function" == typeof require && require;
                if (!h && i) return i(g, !0);
                if (f) return f(g, !0);
                var j = new Error("Cannot find module '" + g + "'");
                throw j.code = "MODULE_NOT_FOUND", j
            }
            var k = c[g] = {
                exports: {}
            };
            b[g][0].call(k.exports, function(a) {
                var c = b[g][1][a];
                return e(c ? c : a)
            }, k, k.exports, a, b, c, d)
        }
        return c[g].exports
    }
    for (var f = "function" == typeof require && require, g = 0; g < d.length; g++) e(d[g]);
    return e
}({..........
....

Upvotes: 1

Related Questions