l.js: Load CSS and JavaScript files in parallel

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-01-16 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 261 This week: 1All time: 164 This week: 17Up
Version Licenses JavaScript version Categories
ljs 1.0GNU General Publi...1.0HTML, jQuery
Description Author

This object can be used to load CSS and JavaScript files in parallel.

It can queue given CSS and JavaScript files to be loaded at the same time the rest of the page is loaded. It keeps track of loaded files to avoid loading each of them more than once.

A callback function may be called when each CSS and JavaScript file is loaded.

  Performance   Level  
Name: Jonathan Gotti <contact>
Classes: 8 packages by
Country: France France
Age: 41
All time rank: 262 in France France
Week rank: 18 Up1 in France France Up
Innovation award
Innovation award
Nominee: 5x

Winner: 3x

# l.js is another simple/tiny javascript/css loader

## features
- parallel script / css loading
- callback after script loading (css support callback too but are executed imediately)
- tiny only 2.1ko uglifyed, less than 1ko gziped (at least for latest revision)
- may load in order to preserve dependencies
- support aliases for simpler calling
- on demand loading
- only one script tag required
- clear syntax
- successive load of same file will load it once but execute all callbacks associated
- can dumbly check already inserted tags at load time
- may use a fallback url on error (only for js files and with error events compatible browsers)

## examples

### loading ljs and another libs with one single tag
<script src="l.js">
	ljs.load('myLib.js',function(){ /* your callback here */});
or using rawgit CDN:
<script src="https://cdn.rawgit.com/malko/l.js/v0.1.1/l.min.js">
	ljs.load('myLib.js',function(){ /* your callback here */});

### loading some scripts in parallel others in order
<script src="l.js">
		.load('myRequiredLib.js','myDependentLib.js',function(){ /* your callback here */})
second load will be executed in parallel of first load but myDependentLib.js won't load before myRequireLib.js is loaded

<script src="l.js">
	ljs.load(['myLib.js','myRequiredLib.js'],'myDependentLib.js',function(){ /* your callback here */});
this will load myLib.js and myRequiredLib.js in parrallel and wait for them before loading myDependentLib.js

### using some aliases for simpler loading
<script src="l.js?checkLoaded"> // <- adding checkLoaded to the url will dumbly check already inserted script/link tags
			jQuery:'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#jqueryId' // <- script tag will have attribute id=jqueryId
			/* work with both jquery and jquery-ui here */

### define a fallback url
l.js also support a fallback url for javascript files in case you want to try to get the resource from another location on loading failure
You can define this fallback url parameter like you define ids. The difference is you will prefix with **#=** instead of # alone
<script src="l.js">
			generated script tag will have myid as id and will try to load /myfallback.js if it fail to load http://domain.com/myLib.js
this piece of code is dual licensed under MIT / GPL
Hope this help, code review, suggestions, bug reports are welcome and appreciated.
  Files folder image Files  
File Role Description
Accessible without login Plain text file bower.json Data Auxiliary data
Accessible without login Plain text file build.sh Data Auxiliary data
Plain text file l.js Class source code
Plain text file l.min.js Class minified code
Accessible without login Plain text file README.md Doc. documentation

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:164
This week:17Up