AMD loaded scripts not visible in chrome

69 Views Asked by At

I am trying to load a script into a plugin I'm writing using an AMD style pattern. I'm not using any AMD libraries (curl,require) because I want to minimize dependencies in the plugin. I'm successful at loading the script and returning the object the way I want it, but I am having a hard time debugging the script because it won't show up in chrome's debugger (I haven't tried firefox yet, but I use chrome for development.)

Can you offer any help or insight into the issue? Do you have any improvements on this script?

    _loadRendererAsync: function () {
        console.info("loading renderers");
        var settings = $.graphicsSettings();
        var renderers = settings.renderers.slice(0);
        while (renderers.length > 0) {
            var renderer = renderers.shift();
            if ($.isPlainObject(settings._renderers[renderer])) { // if renderer has been cached, load it
                return $.when(settings._renderers[renderer]);
            } else if ($.isPlainObject(renderer)) { // if the renderer is a function, return it directly
                return $.when(renderer);
            } else if (typeof renderer === "string") { // if the renderer is a string dynamically load it
                // figure out if the rendere is a url
                var pathToLoad = renderer;
                if (renderer.indexOf("/") == -1)
                    pathToLoad = settings.basePath + "jqgl." + pathToLoad + ".js";
                var dfd = $.Deferred();

                // **** here is the ajax call to pull down the script ****
                $.ajax({
                    url: pathToLoad,
                    dataType: "text",
                    type: "get",
                    cache: true
                }).done(function (text) {
                    settings._renderers[renderer] = eval(text);
                    dfd.resolve(settings._renderers[renderer]);
                });
                return dfd;
            }
        }
    }
1

There are 1 best solutions below

0
On

After deliberating, I decided to use requirejs as an optional dependancy, with conditional code for loading scripts through $.getScript();