Detecting load failures with head.js

287 Views Asked by At

When a required script doesn't load, the callback fires even if the script load fails (404):

function callback () {
    console.log('callback,', arguments);
}

head.test({
    test: 1 === 1,
    success: ["/non-existant.js"], 
    failure: [],
    callback: callback
});

In the above example, the console outputs this regardless of whether or not the script file is loaded:

callback, []

Is there a way to handle that?

1

There are 1 best solutions below

1
iMatoria On

If you want to know what file was loaded, than you always know it via your test condition. But, if you seeking that if your /non-existant.js file fails to load than your failure scripts should load than you are getting this test function wrong.