News for hackers. Stuff that matters.
Re:The only script in your head by dinedal on Tuesday November 30, 2010 @02:21PM (#1955236)
I wish it was just the script loading and the other stuff was in a separate library. For a script that purposes to make less loading times I find it ironic that it would also throw in the kitchen sink.
Re:The only script in your head by philfreo on Tuesday November 30, 2010 @03:23PM (#1955440)
If all you need is an easy way to asynchronous / lazy load JavaScript, you can just include something like this: http://friendlybit.com/js/lazy-loading-asyncronous-javascrip...

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;
    });
Re:The only script in your head by timmaah on Tuesday November 30, 2010 @02:55PM (#1955355)
https://github.com/headjs/headjs/blob/master/src/head.loader...

Head Loader: The ultimate JavaScript loader. Can be used as a standalone tool.

Re:The only script in your head by storborg on Tuesday November 30, 2010 @04:51PM (#1955723)
The latency difference between an HTTP req for a 2.3K script and a 500 byte script is pretty trivial. And if you're concatenating with other js assets on your site, the incremental increase in size after minification/gzipping will probably be even less than 2.3K.
Re:The only script in your head by kilian on Tuesday November 30, 2010 @04:33PM (#1955660)
Try out LABjs: http://labjs.com/
Re:The only script in your head by patrickaljord on Tuesday November 30, 2010 @07:05PM (#1956162)
Or http://yepnopejs.com/ it comes with conditional loading, based on labjs.
Re:The only script in your head by chrisbroadfoot on Tuesday November 30, 2010 @07:07PM (#1956168)
Agreed. It looked good until I started reading about CSS. The other stuff should be loaded asynchronously, as per their (wise) suggestion
Re:The only script in your head by trafficlight on Tuesday November 30, 2010 @02:56PM (#1955357)
Absolutely. The javascript loader sounds interesting, but I don't need any of the CSS, HTML5 or screen size detection.
Re:The only script in your head by alanh on Tuesday November 30, 2010 @09:27PM (#1956543)
You don’t understand the philosophy and failed to realize there are already number of scripts that already do this. (Let’s ignore that you you referred to 2K as “the kitchen sink.”)

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…