Helium, the JavaScript package server
Helium hosts versioned copies of JavaScript libraries checked out from Git, and lets you load objects from these libraries on demand. It uses Jake to build each library and extract dependency data, and JS.Packages to resolve dependencies and load files at runtime. The package manifest is generated using data extracted during the build process.
To use libraries from this server, drop the following in your HEAD:
<script src="http://he.jcoglan.com/js/helium.js"
type="text/javascript"></script>
<script type="text/javascript">
// Specify which branch/tag of each Git project to use, e.g.
// Helium.use('yui', '2.7.0');
// Helium.use('ojay', '0.4.1');
</script>
Use the require() function throughout your pages to load JavaScript
objects on demand. Dependencies are automatically handled for you:
<script type="text/javascript">
require('GMap2', 'YAHOO.util.Selector', function() {
var box = document.getElementById('mapview'),
map = new GMap2(box),
links = YAHOO.util.Selector.query('a');
});
</script>
To set up Helium, you’ll need to add projects to deploy using YAML format. Each entry should be the name of a project followed by its Git URL. Helium relies on JS.Class, for which you need to set a Git URL and a version to use:
--- js.class: repository: git://github.com/jcoglan/js.class.git version: 2.1.x projects: your-library: git://github.com/your/library.git
You may also want to add some custom loaders for libraries not deployed using Helium. For example the following are loaders for Google Maps:
/**
* Loads the `google.load` function, required to load other
* parts of the Google API. Requires `Helium.GOOGLE_API_KEY`
* to be set beforehand.
**/
loader(function(cb) {
var url = 'http://www.google.com/jsapi?key=' + Helium.GOOGLE_API_KEY;
load(url, cb);
}) .provides('google.load');
/**
* Loads the Google Maps API. Requires `Helium.GOOGLE_API_KEY`
* to be set beforehand.
**/
loader(function(cb) { google.load('maps', '2.x', {callback: cb}) })
.provides('GMap2', 'GClientGeocoder',
'GEvent', 'GLatLng', 'GMarker')
.requires('google.load');