3 ms·
https://github.com/walmartlabs/little-loader https://github.com/walmartlabs/little-loader is smaller (519 bytes min+gzipped), supports IE8, and fires either on
by pygy_ 10y ago
https://github.com/walmartlabs/little-loader https://github.com/walmartlabs/little-loader is smaller (519 bytes min+gzipped), supports IE8, and fires either on script load or on error synchronoulsy (so that globals won't be overwritten by code that runs between script loading and the callback firing). The thing is tested on SauceLabs down to IE8.
The drawback is a lower level API, and it is JS only. AFAIK loading CSS consistently cross browser is also a mine field if you want consistent error handling.
window._lload("http://example.com/foo.js", function (err) {
// `err` is script load error.
// otherwise, foo.js is loaded!
}/*, [optional context (`this`) variable here] */);
- andres 10y agoThe original bare-bones version of LoadJS was down to 455 bytes and grew to 710 as we added some useful features (e.g. CSS loading, async false support, load retries). Initially I was hesitant to add CSS support because handling load errors across browsers is very tricky but I think we came up with a good solution [1] that is tested down to IE9 [2]. [1] https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L109-L119 https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L... [2] https://github.com/muicss/loadjs/blob/master/test/tests.js#L188-L301 https://github.com/muicss/loadjs/blob/master/test/tests.js#L...
- pygy_ 10y agoGood job on detecting CSS loading failures. The little-loader also has a section to detect JS loading and errors in IE8/9 (with a dedicated sub-section for the former), I didn't see anything like this in LoadJS... Did you find a terser workaround? https://github.com/walmartlabs/little-loader/blob/42d233f360162bb01fce5a9664b6ef54751bd96e/lib/little-loader.js#L101-L207 https://github.com/walmartlabs/little-loader/blob/42d233f360... I'm somewhat familiar with little-loader because I've worked at making it smaller, but I'm not competent to judge whether its approach is necessarily the best...
- andres 10y agoWe use the `onerror` handler to detect load errors on IE9: https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L106-L134 https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L...