Non-existant file still gets its success callback called
Closed this issue · 7 comments
The following prints out "shouldnthappen"
$script('doesntExist.js', function() {
console.log('shouldnthappen')
}, function(notFound) {
console.log(notFound)
})
This makes me think script.js isn't in any way production ready.
this is a valid concern but with all respect leave your sarcasm elsewhere. your request to change core is an opinion of which has been purposely decided in the library to load non-existent or errored files. you would otherwise never receive a callback and may mistakenly attempt to wait for an event that may never occur. it's up to the developer to make sure their scripts load properly.
Eg:
$('cdn.jquery.com/latest.js', function () {
if (typeof $ !== 'undefined') ready()
else $script('/js/jquery.js', ready)
})
@ded I'm sorry I offended you. But, I was not being sarcastic in any way. The documentation for this library in no way mentions this (apparently expected) behavior, and given that it very unintuitive, it concerned me. I take error handling seriously, and want the libraries I use to take it seriously too.
no worries. consider taking the above approach. it's a common approach other script loaders take
Will do, thanks
+1 just read this now, pls update README to indicate callback will fire in the event of failure to load the script, been searching for hours for this answer
@kzap - I believe this behavior exists in script.js
because older browsers don't support the onerror
callback. Here's a script loader for modern browsers (IE9+) that has the same API as script.js
and adds support for success/fail callbacks https://github.com/muicss/loadjs