Skip to content
/ fallback Public
forked from dolox/fallback

JavaScript library for dynamically loading CSS and JS files. Also provides the ability to load multiple files from a CDN with multiple fallback options and shimming!

License

Notifications You must be signed in to change notification settings

TopCS/fallback

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fallback.js

*** Tested and working in Chrome, FireFox, Safari, Opera and IE 7 - 10

*** this documentation will be updated shortly. the keys for the JavaScript libraries you wish to load need to be their variable names. for instance jquery is "window.jQuery" so the key needs to be "jQuery" in order for this to work in older versions of IE.

The library is only 2 KB!!!

About

  • JavaScript library for dynamically loading CSS and JS files.
  • Ability to load multiple files from a CDN with multiple fallback options.
  • Load scripts on demand for faster page load time!
  • Loads all scripts in parralel!
  • It's extremely easy to implement!
  • This is the only external script that needs to be loaded in your HTML!

API

fallback.ready([object], function)

[object]

  • Is optional. If object is not passed it will assume it's the callback function.
  • You can pass an array of libraries that you only want to execute your code for.

function

  • Ready expects a function and will execute after load has completed.
  • You can call ready multiple times throughout any of your scripts as it will chain all your functions and execute them upon completion.

fallback.load(libraries, options)

libraries

  • Object that expects its values to be either a string or array of urls.
  • You can pass either an array or string as the value for each library.
  • All libraries will be executing in parallel.
  • The fallback libraries will be executed in the order they are in the array.

options

  • Expects parameter to be an object.
  • callback must be a function, which will return a success and failure object as individual parameters. ex: function(success, failed)
  • shim ability to set libraries to wait in line for other libraries to finish loading.
fallback.load({
	// Stylesheet support. If a file contains .css it will attempt to load it as a stylesheet.
	css: 'index.css',

	JSON: '//cdnjs.cloudflare.com/ajax/libs/json2/20121008/json2.min.js',

	jQuery: [
		'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.FAIL_ON_PURPOSE.min.js',
		'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js',
		'//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js'
	],

	'jQuery.ui': [
		'//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
		'//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
		'//js/loader.js?i=vendor/jquery-ui.min.js'
	]
}, {
	// Only load jquery ui after jquery itself has loaded!
	shim: {
		'jQuery.ui': ['jQuery']
	},

	callback: function(success, failed) {
		// Inline callback
	}
});

fallback.ready(['jQuery'], function() {
	// jQuery Completed
});

fallback.ready(function() {
	// Completed
});

Changelog

v0.3 / 2013-06-14

  • Removed ready_invoke option.
  • Added the ability to pass in an array of libraries to the ready event.

v0.2 / 2013-06-13

  • Fixes for IE 7, 8 and 9.
  • Added MIT license.
  • Added .gitignore
  • Added release branch.

v0.1 / 2013-05-27

  • Initial release.

githalytics.com alpha

About

JavaScript library for dynamically loading CSS and JS files. Also provides the ability to load multiple files from a CDN with multiple fallback options and shimming!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.0%
  • Shell 3.0%