简体   繁体   中英

Require.js requests for Handlebars resources are randomly aborted in IE9

We are developing a web application that uses Require.js and Handlebars, and it works correctly in all browsers except (of course) IE9. In IE9, the requests that are made by the Handlebars Require.js module ( hbs.js ) to load Handlebars resources are randomly aborted - sometimes, they succeed, and when they fail, there is no clear pattern as to which requests fail (other than the fact that only Handlebars requests fail; all requests for JavaScript resources succeed). In the Network pane, the request is listed as (Aborted) , and the initiator is (Pending...) , with no further information.

This is probably not a configuration error, since it works everywhere else, but rather a problem with the frameworks' browser compatibility, so I'm omitting the configuration. Does anyone have any idea about what is going on?

(Note: I have already found the solution after several hours of digging, and will post it myself for the benefit of others who might encounter the same problem. The solution is already described here and here ; however, finding those answers requires that you have already figured out that XDomainRequest might be the problem, which requires digging into the framework code.)

hbs.js uses XDomainRequest in old IE versions. It turns out that, in IE9, when an XDomainRequest request doesn't finish immediately, IE9 will attempt to fire the onprogress callback, and it will abort the request if the callback isn't there. In other words, if you do not subscribe to the XDomainRequest.onprogress callback, your requests will fail randomly in IE9 . The hbs.js version we were using did not subscribe to this event (it has been fixed in recent versions), and adding the subscription fixed the problem:

xhr.onprogress = function() {};

immediately after

if (useXdr) {
    xhr.onload = function () { callback(xhr.responseText); }

in hbs.js .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM