Infos
include.js is a tiny javascript tool made to load asynchronously Javascript or CSS files when you need them (like a include javascript function).
Now that google track page loading time, use this kind of tools can increase your score to appear on the top of results.
This kind of tools are also useful for Web APP's, loading script only when user need them.
Features
include.js don't load script that are already loaded in the page, force to load them asynchronously and can control the presence of a javascript object.
Each file can have a callback and a general callback can be run when each files are loaded.
include.js now support nested dependencies, so you can load a file when an other needed file is loaded
Project
include.js whas created by Capitaine Mousse (Jérémy Barbe) under the MIT License.
The project is hosted by GitHub and everyone can contribute to this project.
Get's started
Insert Include.js in the head or body your document. It just needs an array of files and optionally a callback to run :
include([
"file1.js",
"style.css",
["file2-with-callback.js", function(){ /*do something*/ }],
["jquery-and-callback.js", function(){ /*do something*/ }, "jQuery"],
['other/js/script4.js', function(fn){
//Nested dependencies
include('other/js/script4sbestfriend', fn);
}]
], function(){
//end callback
});