News for hackers. Stuff that matters.
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;
    });

There are no comments on this comment yet.