boxcars is a zero-dependency tiny library for fetching remote resources. It supports both NodeJS and web browsers.
Tested Platforms: Node, IE6, Chrome, Firefox
Install
$ npm install boxcars
Usage
one-liner:
var boxcars = require('boxcars');
boxcars('http://google.com', 'http://amazon.com', 'http://github.com')(function(error, homepages){
console.log( homepages[0] );
});
Defining collections:
var templates = boxcars('templates/foo.html', 'templates/bar.html', 'templates/qux.html');
templates('templates/corge.html', function(error, templates){
console.log( templates.length );
console.log( templates[0] );
});
Passing Objects:
templates({ 'corge': 'templates/corge.html', 'eggs': 'templates/eggs.html' }, function(error, moreTemplates){
if(error) throw error;
console.log( moreTemplates.corge );
});
Preloading:
templates.cache({
'quux.json': '{}',
'templates/foo.html': '<strong>Hello {{ name }}!</strong>',
'templates/bar.html': '<strong>Hello {{ name }}!</strong>'
});
Reset the cache:
templates.cache(undefined);
Testing
Publish the tests and visit localhost:1314 with the browser you want to test.
$ make test
To run the tests on NodeJS:
$ make test do=command cmd=node
To see the summary of the results;
$ make test do=verify