4

Looking for any advice on experiences between these two javascript loaders ?

head.js('some-script-here.js');

Or

$LAB.script("framework.js").wait();

Can anyone provide any guidance on these and whether one is better than another ? I'm struggling to find any articles with comparisons or which is better to use ?

Tom
  • 49
  • 2

2 Answers2

2

I looked into both as well as YepNope, none of which did exactly what I wanted. So what did I do? I wrote my own.

https://github.com/sgarbesi/fallback.js

HeadJS didn't do fallbacks how I wanted it to and neither did LabJS or YepNope.

RequireJS on the other hand somewhat did but the library was way too large. The whole point of this library is for it too be as minimal as possible so the page can actually load as fast as possible.

This will allow you to load as many scripts as you want and have as many fallbacks as you want, it also gives you a function to execute your code in after all the libraries have finished loading.

Worth checking it out, in my opinion was well worth me writing it.

sgarbesi
  • 339
  • 4
  • 6
  • @timw4mail The purpose of the script isn't to combine HTML5 shiv, it's to actually load websites faster by the page not having to wait for the JS to finish loading. The situation being I wanted to load 10-12 JS libaries from a CDN. If any of those CDNs failed, I wanted fallback CDNs, if those fallback CDNs failed I wanted to fallback to my local copies for my users so the website itself did not actually break. If your looking for HTML5 shiv or Modernizr, you would use them separately. I also wanted some of those libraries to depend on others, by example jQuery UI cannot load until jQuery has. – sgarbesi Jun 08 '13 at 18:11
  • really like your library, care to put it onto http://sindresorhus.com/bower-components/ ? – Valerio Jul 16 '13 at 12:36
  • @ValerioColtrè I added it to the Bower repo – sgarbesi Sep 09 '13 at 15:01
0

Better to use in what situation? HeadJS is more versatile than just a javascript loader. For some situations, YepNopeJS would be better than either of these.

timw4mail
  • 1,716
  • 2
  • 13
  • 16
  • exactly - but why is it better and for what reasons ? – Tom Jun 24 '11 at 14:48
  • @Tom I've never used LabJS, but HeadJS combines parts of Moderizer with HTML5 shiv and a javascript loader. YepNope is good for loading different shims based on browser compatibility, or any other situation you need to conditionally load scripts. Also, the quickest way to make javascript to seem faster is to put it at the bottom of the page, where it doesn't block the rest of the page loading. – timw4mail Jun 24 '11 at 16:03