Modernizr load [A, B] seems to execute B before A, how is this possible?-Collection of common programming errors

Modernizr.load({ both: [a, b] }) seems to executes b before a but that’s not how Modernizr is supposed to work? “yepnope.js [used by Modernizr] always executes things in the order they are listed

Modernizr versions 2.5.3 and 2.6.2.

I’m loading angular.js and angular-sanitize.js like so:

Modernizr.load({
  both: [
    cdnDir + 'angular.js',
    cdnDir + 'angular-sanitize.js',
    d.i.assetsUrlPathStart + 'debiki-dashbar.js'],
  complete: bootstrapAngular
})

However, infrequently, angular-sanitize.js dies because angular does not yet exist.

But isn’t Modernizr.load(both: [a, b, c]) guaranteed to execute a, b, c in order? What is happening…?

Details:

The error happens on an angular.extend(...) line in angular-sanitize.js, the last line in this excerpt: (line 148)

// Elements that you can, intentionally, leave open (and which close themselves)
// http://dev.w3.org/html5/spec/Overview.html#optional-tags
var optionalEndTagBlockElements = makeMap("colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr"),
    optionalEndTagInlineElements = makeMap("rp,rt"),
    optionalEndTagElements = angular.extend({}, optionalEndTagInlineElements, optionalEndTagBlockElements);

Here’s the error message:

Uncaught TypeError: Cannot call method ‘extend’ of undefined ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular-sanitize.js:148

and Chrome’s debugger shows that window.angular is indeed undefined – althought it’s being used on the very last line in angular.js (which is supposed to be executed first of all).

Chrome (version 24.0.1312.57) says that both angular.js and angualar-sanitize.js are loaded from the browser’s cache.

Update: This more explicit rewrite really should work I think. But when run, it sometimes prints “Angular absent” and dies later on (when angular-sanitize.js runs)- although Angular “must” just have been created.

Modernizr.load({
  load: cdnDir + 'angular.js', //

Originally posted 2013-11-29 06:17:32.