|
Project Information
Links
|
yal.js, the micro size JS loaderyal.js on githubIf you prefer: https://github.com/WebReflection/yal.js aboutyal.js is a truly tiny library partially inspired by both LAB.js and yepnope.js projects. In about 0.6Kb minzipped yal does really few things but it does them right:
compatibilityyal.js has been tested against many IE, Chrome, Safari, Firefox, Opera, Webkit, and respective mobile versions, in different platforms, and without problems. You can check results against all browsers, if it's green, it passed, if it's red, it failed (no reds), if it's white, something went wrong with the testing tool and not with yal.js or JavaScript was disabled: test page http://www.3site.eu/yal/wait.html crossbrowsertesting http://crossbrowsertesting.com/users/32945/screenshots/z30790cabfdc044b8e50/public browsershots http://browsershots.org/http://www.3site.eu/yal/wait.html exampleyal
.script("1.js")
.wait(function () {
init1(); // core dependency with initialization
})
.script("2.js", "3.js") // no need to call script N times
.wait() // since 4.js, if present,
// depends on 2 and 3
.script(function () {
if ( // features detection example
/iOS/i.test(
navigator.userAgent
)
) {
return "4.js";
}
})
.wait(function () {
initAllBut1(); // ready to go
})
;why another JavaScript loaderThe reason is quite simple: I don't need everything LAB.js has to offer, I like yepnope simplification and features detection purpose, but I still go nuts when I cannot grab a portion of a library, aka: only what I really need. LAB.js is surely complete and quite standard, but as is for jQuery library, it must include a lot of code that is redundant or superfluous beceause never executed in my daily basis target browsers. I also noticed developers are basically using only .script() and .wait() and I was not interested into all other possible features or, even worse, extremely uncommon edge cases. Moreover, in my past I have created many loaders, related to JS or not, so it was both fun and trivial to create this tiny script which works, at least for what I usually need, and it does not add relevant code size to whatever project you are working on. why chose yal.js against othersI am not selling anything here and I would like to be as clear as possible about yal and its potentials against other solutions.
why not chose yal.js against othersWell, no software is perfect so neither is yal. Here a list of reasons you may consider before you decide to use or not this library
yal is both serial and fully or partially parallelThe basic/default version of yal uses parallel downloads in between .wait() calls. This means that every time there is such call, scripts defined after won't be downloaded until the precedent yal.wait([optionalFunc]) has been executed. There are many tricks to trigger a script preload but unfortunately these techniques are not completely cross platform or cross browser yet. For this reason the basic version of yal uses a complete KISS approach: the best compromise between performances, reliability, and control over loaded code execution ... also without any waste of precious bytes. more about yal.js and forced parallel downloadsEvery assigned script will create an object or an Image that will be appended on the DOM in order to trigger the browser download. At that point when it's time for the current script to be downloaded there are two options:
It must be said it's based on a sort of browser network layer hack ... it won't hurt but there is no guarantee that it will produce same advantages in the future. Well, in that future I will update the script using de-facto standards to preload scripts: YAGNI ;-) Enjoy, Andrea Giamamrchi |