

The only script in your head - timf
http://headjs.com/

======
dinedal
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.

~~~
philfreo
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...](http://friendlybit.com/js/lazy-loading-asyncronous-
javascript/)

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;
        });

------
CWIZO
The idea seems nice, I'd have to test it out to actually see if it really
delivers. One thing that bugs me tho is the tone of the text. It's all "this
is the best thing since sliced bread" and "authors surly must be at least
demi-gods". This comment in the page's source says it all really:

"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

~~~
tofumatt
The presentation is there to convince you to use their script. I think _more_
OSS libraries and software should convey such an attitude; I'm way more
inclined to use software when the authors tell me that it's awesome and why.

~~~
paulirish
Well it's this author's mistake to be so entirely confident when the library
is still full of problems: <https://github.com/headjs/headjs/issues#list>

~~~
tipiirai
hello.

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...](https://github.com/headjs/headjs/blob/master/src/head.loader.js)

About the tone: maybe yea. maybe not. that's how I feel right now.

~~~
paulirish
thx for the fixes, tero. :)

------
Sephr
I don't understand the whole dynamic class selectors for "Screen size
detection". If it's trying to add support for standards, it should support
media queries instead.

~~~
alanh
Your response would be appropriate if we were talking about a _new browser_
but the fact is, virtually no non-Webkit browser, especially on Mobile,
supports these media queries. Web dev is all about working with the browsers
we’ve got, not the ones we want.

~~~
Sephr
I'm talking about making headjs add support for media queries (viewport size,
at least).

------
Griever
I've been reading up alot on javascript loaders lately to see which one I
should use in the webapp I'm currently building.

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?

~~~
bretthopper
I've used LABjs and it worked great. It's also the most "focused" loader in
the sense that it only does javascript loading. RequireJS also includes a
module system and some optimization tools. headjs unnecessarily includes CSS
feature detection and screen resolution.

If you want feature detection, nothing is better than Modernizer:
<http://www.modernizr.com/>

~~~
Griever
Thanks! Yeah I've become quite accustomed to using Modernizr (thanks to
inclusion in the Html5Boilerplate).

LABjs always seemed like the most straightforward to me, so its nice to hear
that others agree :)

~~~
patrickaljord
give yepnope a try <http://yepnopejs.com/>

------
forgotAgain
If most of your javascript is made up of libraries like jQuery wouldn't it be
simpler to use a free CDN like Google or Microsoft so that the library is most
likely already on the user's machine? That would appear to be have a better
payback than adding another library to load.

~~~
chrisbroadfoot
Yes. Check out the Google AJAX API.

<http://code.google.com/apis/loader/index.html>

------
kqueue
IMHO, websites should include a single js file. In development you can have
100 js files, but in production these should be combined into a single file.

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.

~~~
superk
I'm not sure I agree with this. I don't think a user should have to re-
download all the JS on the site if I just change a single line. Small changes
probably happen frequently and shouldn't invalidate the entire JS cache. If I
were using a framework like jQuery, I would link that separately from a 3rd-
party CDN like Google. Then all the shared behavior would be another request,
and page specific code a third. In most cases I would be changing the page
specific code which would only invalidate the cache for that request on that
page. IMO that's a better compromise.

------
tjarratt
I've wanted something exactly like this for a while now. Looking forward to
trying this in a few projects over this next week.

------
tonyskn
RequireJS does this and includes a module system for managing dependencies. It
is also available as a JQuery plugin.

------
adamstac
Logged. <http://lg.gd/46>

------
aaront
Very interesting. Will have to try this for some of my projects.

