Where jammit falls in love with javascript.
jammit provides the ability to package, concatenate and compress javascript and CSS resources and allows you to pre cache assets by using the eponymous utility. However, to take advantage of the packaging and templating facilities the application has to be running in a Rails environment. This is where gettit comes in.
With gettit, you can take advantage of all the jammit goodness - assets manifest, packaging based on environment, debug mode, javascript templating (jst), etc. - without Rails. In place of the jammit Rails templating, gettit uses a simple javascript api to load packages on demand.
Backbone.js todo app that is loaded with gettit.
The following is an example manifest file (assets.yml) you would use for dependency management and building in jammit:
package_assets: on
compress_assets: on
template_function: _.template
javascript_compressor: closure
javascripts:
scripts:
- js/model/content.js
- js/template/content.jst
common:
- js/common/string.js
- js/common/template/menu.jst
stylesheets:
styles:
- css/common/style.css
To load packages in production and development, gettit gives you the ability to create and re-use loaders to load packages from your jammit configuration:
<script type="text/javascript" src="gettit.js"></script>
<script type="text/javascript">
var loader = gettit.getLoader({
assetsConfiguration: 'assets.yml',
environment: 'development',
assetsPath: '',
buildPath: 'build/'
});
loader.get(['scripts', 'common'], 'styles', function() {
// Take care of business after the packages have loaded.
});
</script>
Uses the following options to return a package loader:
assetsConfiguration
: Path to the jammit assets config file, relative to theassetsPath
or a full url.assetsPath
: Pre-pended to asset paths when fetching.environment
: gettit supports "development" or "production" modes for package loading. In development, gettit will load scripts, templates, and stylesheets defined in the jammit manifest from the givenassetsPath
. In production, jammit will use thebuildPath
to load the jammit compressed packages.build ath
: Prepended to production asset packages when fetching in the production envrionment.version
: Optional parameter appended to urls to bust browser cache in production. Usually this property would be dynamically configured for each production build.callback
: Optional callback that will be called after all of the packages are loaded.isDebugging
: Defaults to false, but if true, this loader will be configured to always load in debug/development environment.
var loader = gettit.getLoader(options)
Loads asset packages with three parameters: list of javascripts packages, list of stylesheets packages, and an optional callback. If only one javascript or stylesheet package is needed, then a single package name (string) will suffice.
loader.get(['scripts', 'common'], 'styles', function() {
// Take care of business after the packages have loaded.
});
As defined by jammit, gettit will respect the debug_assets=true
url param-value when loading in production, and load the individual assets instead of the packages.
If assets are fetched cross-domain when using debug mode in production, or in development, then CORS support is required on the server that houses the assets.
Browser support is the same as lab.js support, unless files in production and/or development are being fetched cross-domain, which requires CORS support, and mostly affects IE, requiring version 8+.
Unfortunately, you can't use glob rules in the jammit configuration/assets file because gettit wouldn't know how to expand the patterns for fetching files and paths.
MIT
- The WHOLE API changed - gettit is a required script and the api was changed to construct package loaders.
- Initial release (extracted and cleaned up from various javascript apps).