Skip to content

1boeman/laad.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

JavaScript script loading libraries (yep-nope.js, require.js, Lab.js, head.js $script.js, etc.js, etc.js) are quite ubiquitous nowadays.
In fact there's so many that the time it takes to compare them all is more than enough to write your own.

Here's mine. It limits itself to the most basic of tasks, namely loading and executing scripts.

The code below will load any files requested only once, and use the internally cached version afterwards until page refresh.

Simple to sum up:

Load a script asynchronously, with callback:

laad.js('path/to/script.js',function(){
	alert('loaded');
})

or without callback:

laad.js('path/to/script.js')

Load another script but wait for the previous queued script to finish loading (for dependency's sake):

laad.js('path/to/library.js');
laad.wait('path/to/script2.js',function(){
	alert('loaded');
});

add a bunch of (mutually independent(!)) scripts asynchronously and execute a single callback when they've all finished loading:

laad.js(['path/to/script2.js','path/to/script3.js','path/to/script4.js'],function(){
	alert('loaded all of them');
})

Use the pathConfig property to make abbreviations for paths in loading statements:

laad.pathConfig = {
	"jqui"		:"js/jquery-ui-1.9.2.custom.min.js",
	"main"		:"js/main.js"
};
laad.js('jqui');
laad.wait('main',function(){
	alert('loaded'); 
});

About

Pretty simple asynchronous script loading - laad.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published