mootools/mootools-more — Issue #1108: assets.javascript load error handling inconsistent (have simple fix)
Author: jvermette
Created: 2012-02-29 20:28:33+00:00
State: open

assets.javascript defines the "load" event. For IE, it defines the readystatechange event.

In IE (7/8/9, probably all), readystatechange returns "loaded" when the file is not found, and any provided "onLoad" event is called. In other browsers (Safari, FF, Chrome) there is no event handling triggered for load failure and onLoad is never called.

I am using onLoad to cascade some serial javascript file loads. One of them was failing, and in Safari/FF/Chrome that caused the chain to break because the onLoad is never called. In IE it succeeded because onLoad is always called no matter what.

Since IE has this behavior, where it is not possible to distinguish between success and failure, is it is not possible to have an error event -- but the "call onLoad on failure" behavior can be made consistent.

The simple fix (tested, Safari/FF/Chrome/IE) is one-line. Instead of this:
"""
script.addEvent('load', load);
"""
do this:
"""
script.addEvents({'load': load, 'error': load});
"""