Projects: Reload-JS (v0.1)

Reload-JS is a javascript live loader whose goal is to be simple and light weight. I created Reload-JS while working on an Infographics Landing Page, and embedding solution, for Newlogic USA. I needed to load and check for any libraries I need (namely jQuery). The loading part has been taken care of in this version, but I am trying to figure out how to include tests for each library, to make sure no override occurs (my jQuery doesn’t break or overwrite the loaded pages jQuery).

More after the jump.

Here is the Reload-JS source code. It is simple and it doesn’t really do anything special. Most of the code has been used previously and is very popular for live loading. It accomplishes its task by using a recursive set of callbacks and has a few ways to call it.

First you can use the following:

Or this

My personal favorite is this following call:

You see Reload will automatically append the js if you don’t already have it attached. This is a nice feature to make nice simple calls like above. Reload allows you to set your primary library location and then takes care of it too. This makes loading multiple libraries pretty nice. However, what if you need to use a different host for one of your libraries? No worries! just make sure you use http:// and Reload will detect that it shouldn’t append your default library location to your URL (absolute URL handling).

Reload also has the ability to load from a variable it holds called libs. This can be risky, if multiple people try to use it and is not suggested unless you are sure no one else is using Reload.

Here is the code (and decently commented):

Enjoy!