walmartlabs / little-loader

A lightweight, IE8+ JavaScript loader
MIT License
370 stars 28 forks source link

Feature: Add `script.onerror` handler. #15

Closed ryan-roemer closed 8 years ago

ryan-roemer commented 8 years ago

New API:

window._lload("http://example.com/foo.js", function (err) {
  if (err) { console.log("OH NOES", err); }
  // foo.js is loaded!
}/*, [optional context variable here] */);

/cc @PeoB

exogen commented 8 years ago

Just adding a note here that for old-IE we'll need a disclaimer, because onerror unfortunately just doesn't work. (Although, who knows, maybe everyone else just got that wrong too and we can find a way :wink:).

Having a timeout option could come in handy, especially in that old-IE case where it could be the stand-in for onerror. The problem with having a timeout is that you can't guarantee that the script won't still load after your timeout fires (there's no way to cancel the script loading across browsers AFAIK), so the code could still be executed after you've handled the timeout...

ryan-roemer commented 8 years ago

UPDATE: Error capture works so far for all but IE8 for a 404'ing script.