Some Javascript/Ajax projects: “LABjs” and “mpAjax”
I wanted to slightly diverge from flensed project discussions for this post to talk briefly about two other projects I’ve recently released. The reason for talking about them here is that one or both of them may find some cooperative use or even code sharing with flXHR/flensed in the next version releases, so there is a symbiotic relationship between them.
The first project is called LABjs (Loading And Blocking JavaScript). Put simply, this is a little tool (2.5k compressed) that lets you load Javascript assets dynamically, in parallel, but still allows you to define “blocking”, which is to wait for one or a set of scripts to load before executing other code, such as perhaps loading more scripts.
The main purpose of LABjs is to load scripts dynamically, in parallel, instead of old-school <script> tags which only load one at a time, and block everything else on the page. This significantly speeds up your page load. At the same time, you do sometimes still need to block and wait for some script to get loaded before doing other things. So, you get both in one simple loader API.
For instance, say you’re on a page that needs jQuery, but also needs a number of jQuery plugins. You need to load jQuery core itself, blocking on that download, and the ideally load all the other plugin files afterwards, in parallel, to get the page rendered and functional as quickly as possible. LABjs makes this type of functionality drop-dead simple.
So, this old style of <script> tags:
<script src="jquery.js"></script>
<script src="jquery.myplugin1.js"></script>
<script src="jquery.myplugin2.js"></script>
<script src="jquery.myplugin3.js"></script>
Becomes:
$LAB
.script("jquery.js")
.block()
.script("jquery.myplugin1.js")
.script("jquery.myplugin2.js")
.script("jquery.myplugin3.js")
.block(function(){
// init myplugin1, 2, and 3
});
LABjs is now in v0.7, and is demo’d and hosted on: http://labjs.com.
As I said, this type of loading logic is powerful and clean, and will probably replace the code loading logic in flensed/CheckPlayer/flXHR projects for their next releases.
Joe McCann wrote a great blog post describing and showing off the LABjs tool.
Next up, I’m gonna talk about mpAjax, which allows for easy parsing of multi-part Ajax responses.