

Load.js: A small script to lazily load js - xtacy
https://github.com/chriso/load.js

======
tlrobinson
If I understand this correctly you have to figure out the correct order for
the dependencies to be loaded yourself.

This does not scale. A better solution for larger applications is for
individual files to declare their dependencies, then determine the order to
load them implicitly.

CommonJS modules are the de-facto standard for doing this on the server, and
they're starting to be used in the browser as well.

~~~
Swizec
That sounds like a pretty silly drawback.

A much cleaner solution would be using window.onload to load _all_ javascript
and then only starting execution on document.ready.

That way you pretty successfully get around the issue of ordered dependancies
because at execution time everything is already loaded. If load.js doesn't do
it this way I am profoundly interested as to what the reasoning behind this
might be ... perhaps all browser don't differ between window.load and
document.ready? (or maybe I'm being stupid in some way or another)

~~~
weixiyen
What you are describing is not lazy-loading. The purpose of lazy loading is to
avoid the overhead of having to load all your javascript immediately at the
cost of more server requests later on as needed.

The benefits of speed gained from lazy-loading can be huge in large
applications with little to no browser refresh.

The problem with lazy loading javascript in the browser is you have no good
way innate to javascript to automatically tell if a script has really been
loaded, and the problem you must solve is finding out when you are allowed to
execute commands that have dependencies in the lazy loaded scripts.

~~~
Swizec
Thanks for the explanation, was almost certain I was thinking about it wrong
:)

------
Pewpewarrows
This looks nice, but what does it offer that RequireJS and LABjs don't?

~~~
sjs
I'd use RequireJS or LABjs before this, however it's based on a
"microframework" called chain.js which looks pretty cool.

------
juddlyon
Lab.js is also worth checking for script loading.

------
rorrr
JS to load other JS never made sense to me.

~~~
Pewpewarrows
First off, you shouldn't be down-voted for your opinion. If you agree or the
comment adds to a discussion, up-vote. If you disagree, do nothing. If the
comment is off-topic, asinine, or detracts from the discussion, only then
down-vote. Come on HN, you should know better.

There's a lot of reasons to load Javascript from Javascript. One of the main
ones that crop up is when you're building large single-page web applications
that involve a lot of files that may or may not be dependent on one another.
This allows you to start executing some of your page-specific Javascript as
soon as the libraries it depends on become available, before the rest of your
bulky resources finish loading.

