jsdefer icon indicating copy to clipboard operation
jsdefer copied to clipboard

isLoaded feature

Open wforney opened this issue 13 years ago • 4 comments

When a script is loaded on the page via script tag and then jsdefer tries to include it jsdefer should test for it.

jsdefer should provide a boolean expression test configurable in the script definition via deferDef... The old Sys.loader had this feature and it allows conditionally including a script based on how you define it. There are lots of uses for this...

Load script B only if script A is there (assuming you're not using jsdefer exclusively for script loading (we can't totally enforce it in some of our scenarios).

wforney avatar May 09 '11 21:05 wforney

Also ensure that jQuery version present on page is at least 1.5 due to failure of fail method otherwise.

wforney avatar May 20 '11 17:05 wforney

deferDef has a loaded property on each definition that is an expression. This is a temporary way to use this for now:

jsDefer.deferDef({ jQuery: { bare: true, url: ASPNETCDN + "/jQuery/jquery-1.6.1.js", urlMin: ASPNETCDN + "/jQuery/jquery-1.6.1.min.js", loaded: !!window.jQuery },

...

wforney avatar Jun 10 '11 20:06 wforney

The workaround here is to make loaded a string like:

jsDefer.deferDef({ jQuery: { bare: true, url: ASPNETCDN + "/jQuery/jquery-1.6.1.js", urlMin: ASPNETCDN + "/jQuery/jquery-1.6.1.min.js", loaded: "!!window.jQuery" },

This string then gets eval'd by jsdefer.

wforney avatar Dec 19 '11 21:12 wforney

Also, there is a bug in jsdefer, the loaded gets set to false always, even if you specify it. Workaround is to put this in jsdefer in the defer function:

        var i, readyName, asyncLoad, result, prevPromise,
                runWait = 0,
                delayDomReady = options.delayDomReady || deferSettings.delayDomReady,
                min = options.min || deferSettings.min,
                scriptDef = getScriptDef(scriptName, basePath),
                url = scriptDef.url,
                loadUrl = (min && scriptDef.minUrl) || scriptDef.url,
                settings = jsDefer.extend(scriptDef, options),
                bare = settings.bare || scriptDef["bare"],
                contains = settings.contains || scriptDef["contains"],
                loaded = settings.loaded || scriptDef["loaded"],
                depends = settings.depends || scriptDef["depends"],
                multiple = settings.multiple || scriptDef["multiple"],
                parentPromise = scriptDef.prntPrms,
                promise = scriptDef.promise,
                runCb,
        //thisPromise,
                hasRun, hasRunPromise;

wforney avatar Dec 19 '11 21:12 wforney