Javascript lazy loading
What would you say to: $script.lazy('jquery-latest.min', 'jquery'); //just define a handler
//load when script is requested $script.ready('jquery'....
Is it hard to implement?
nope. it wouldn't be difficult at all. and script.js should in fact be able to support the ability to say $script.ready('jquery', fn) without having to define it first. Thus whenever you're ready to handle the script, you would just fire it off with $script('jquery.min.js', 'jquery')
but in other words I'll look into it
Idea is to have one dependency global file where I can define all js modules and then just load them without worry what version it is. That is also alternative to , function(depsNotFound) { // foo.js & bar.js may have downloaded // but ['thunk'] dependency was never found // so lazy load it now depsNotFound.forEach(function(dep) { $script(dependencyList[dep], dep) }) Thank You :)
@xorock array.forEach is not supported in IE 6-8. Use var i = depsNotFound.length; while(i--) { ... } https://github.com/ded/script.js/pull/48
I'd love this. I came here looking for the same idea. I want to define my dependency chain in $script, AND, incase of other scripts load first, define ready() before the id is defined.
Or another way to say it: I want to retrieve scripts without executing them. Or, alternatively, retrieve and execute only when they're explicitly asked for, resolving all of their dependencies.