SlexAxton/yepnope.js — Issue #88: version >1.5.0 leaves Opera crippled, always waits for errorTimeout
Author: bugdebugger
Created: 2012-02-10 00:10:16+00:00
State: open

yepnope cripples Opera unnecessarily, because it now always waits for the whole ```errorTimeout``` time span (default: *10 seconds !!*), before it calls the ```callback```/```complete``` callbacks. Even when the resource is actually loaded immediately and successfully.

This happens because ```strJsElem``` ends up getting set to ```script``` instead of ```img```.

This regression was introduced first in yepnope v1.5.1. Some commits involved in the matter follow below, notice the changes around the ```strJsElem``` / ```isOpera``` / ```isIE``` code and how the partial *"revert"* in v1.5.1 caused this.

* [2dc5e39 Switched all preloading over to images except for gecko][2dc5e39] somewhere between 1.0.2 and 1.5.0b
* [a979cc0 Reverted back to using script tags with bogus types to preload in IE][a979cc0] one of the two commits for 1.5.1
* [4f1f12d v1.5.2][4f1f12d] removes the unused ```isOpera``` flag.

Test case is provided at jsbin.com:

* [Test case 1][broken] with yepnope 1.5.2, *"broken"* in Opera but works normally e.g. in Chrome/IE
* [Test case 2][monkeypatched] with yepnope 1.5.2, fixed via duck punching before yepnope is loaded
* [Test case 3][working] with yepnope 1.5.0, works in Opera

The test case simply loads jquery v1.7.1 from the CDN and displays when the callbacks are called. You will notice that in *Test Case 1* there is exactly a 10s wait in Opera before the callbacks are run. Although the jQuery file has finished loading long before that. But there is virtually no wait in e.g. Chrome/IE. Test case 2 and 3 show the expected behavior for Opera.

All Opera versions on all platforms should be affected by this (I tested with Opera 11.61on Win XP/7). Also all Modernizr builds with yepnope included (since ~ February 6th) will be affected too.

Possible fix: Reintroduce the ```isOpera``` flag and change

```javascript
strJsElem = isGecko ? "object" : isIE ? "script" : "img",
```

to

```javascript
strJsElem = isGecko ? "object" : (isIE && !isOpera) ? "script" : "img",
```

[broken]: http://jsbin.com/ureqiz/1
[monkeypatched]: http://jsbin.com/ureqiz/4
[working]: http://jsbin.com/ureqiz/2
[2dc5e39]: https://github.com/SlexAxton/yepnope.js/commit/2dc5e39
[a979cc0]: https://github.com/SlexAxton/yepnope.js/commit/a979cc0
[4f1f12d]: https://github.com/SlexAxton/yepnope.js/commit/4f1f12d