www.ThimbleOpenSource.com

Custom libraries loader for jQuery


I was looking all over internet for simple and reliable script and library loader. I have tried yepnope, require.js and others, but there was always some problem with multiple loading libraries simultaneously.

So I have come up with my own jQuery snippet, which takes care of this and works reliably. You just specify what scripts and CSS files are necessary for certain function to work and Custom libraries loader for jQuery loads them and executes callback, when they are loaded.

Requirements

jQuery 1.7+

Configuration

Definition of libraries as simple Javascript object. These can be javascript files, CSS files, located even on external URLs.

var libraries = {
  'tablesorter':['/ js/jquery.tablesorter.js'],
  'qtip':['/js/jquery.qtip2.js', '/css/jquery.qtip2.css'],
  'google_loader':['https://www.google.com/jsapi']
};

Usage example

Usage is simple. Just call library() function with first parameter being library name and second callback to be run when are all scripts loaded for this library.

library('tablesorter', function(){
  $('#table').tablesorter();
});

Download

Zip version (1 kB)

Changelog

July 12, 2013 - released 1.0