The only script in your head
headjs.com
headjs.com
Head Loader: The ultimate JavaScript loader. Can be used as a standalone tool.
Or a nice function, with "Ready" support:
In <head>:
<script type='text/javascript'>
function ljs(s){
var a=document.createElement('script'),
b=document.getElementsByTagName('script')[0];
a.type='text/javascript';
a.async=true;
a.src=s;
b.parentNode.insertBefore(a,b)
}
var Ready=[];
</script>
Then anywhere in the <body> or in any included scripts you can do: Ready.push(function() {
//this will get executed after all the ljs files
});
Then in a script that contains your JS library, append: $.ready(function() { // or some other ondomready fn
// execute all the Ready functions
for (var i = 0, m = Ready.length; i < m; i++) {
Ready[i]();
}
delete Ready;
});However some things need loaded in he head (for using HTML5 tags in IE, for example).
Thus there are obvious efficiencies to be gained by essentially hybridizing Modernizr.js and LABjs.
I’m now watching head.js on GitHub, and suggest you reconsider before dismissing it out of hand…
"headjs :: possibly the most important script after jQuery"
I'm all for cocky and confident attitude, I just think it has no place in a presentational web page/docs
I'm the author of headjs. Have to say here that the release date of this tool was supposed to happen much later. yesterday I came back to github on my regular visit and noticed that it had 100 followers! It was OUT. I don't know how.
anyway. I now stopped all my other work and start focusing on headjs. the bugs will be fixed.
BTW: the loader part of the tool can be used as standalone. Here it is:
https://github.com/headjs/headjs/blob/master/src/head.loader...
About the tone: maybe yea. maybe not. that's how I feel right now.
So far I'm checking out LABjs, RequireJS and now apparently headjs. Unfortunately I am not so sure which will suit me best. Has anybody had any luck with any of the aforementioned three?
If you want feature detection, nothing is better than Modernizer: http://www.modernizr.com/
LABjs always seemed like the most straightforward to me, so its nice to hear that others agree :)
The downside is that you might include things you don't need in all pages, but that's not an issue because the file is transferred once, and cached. This will also minimize future conditional GET requests that check wether the cached file has changed or not.