AMD and CJS dependency management in the browser
JavaScript HTML CSS
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist/recent chore(*): Release of Inject 0.7.2 (via grunt) Sep 3, 2015
examples removed all realySwf instances, need to update tests for this build Nov 7, 2013
src fix #313 where sandboxed iframes causes Inject getDomainName to fail … Oct 24, 2015
tests minor changes to #309/#310, removed tests that fail due to phantomjs … Oct 23, 2014
.gitignore refactor(grunt): Enhanced readability in grunt file Nov 19, 2013
.gitmodules module fix for travis Nov 6, 2012
.jshintignore added jshint options and working travis file Nov 5, 2012
.travis.yml fix(travis) put node_js version in quotes to address travis build error Jul 30, 2014
AUTHORS chore(bower): Creates bower.json file Nov 19, 2013
LICENSE security testing Nov 6, 2013
README.markdown use svg image instead of png for travisCI badge on readme Jul 1, 2014
bower.json chore(*): Release of Inject 0.7.2 (via grunt) Sep 3, 2015
gitcommit refactor(grunt): Enhanced readability in grunt file Nov 19, 2013
package.json chore(*): Release of Inject 0.7.2 (via grunt) Sep 3, 2015
server.js fix (Executor): Improves stacktrace-js integration Apr 21, 2014



Inject (Apache Software License 2.0) is a revolutionary way to manage your dependencies in a Library Agnostic way. Some of its major features include:

  • CommonJS Compliance in the Browser (exports.*)
  • Cross domain retrieval of files (via easyXDM)
  • localStorage (load a module once)
  • Frustratingly Simple

Getting Started With Inject

This page is designed to get you up and running with the latest version of Inject. For greater detail, there is an Advanced Usage section, and a guide to the API.

Download Inject

The latest version of inject is always available via the source repository at The most recent version is usually at the top, and inside is the required JS and optional HTML files. Copy them to your own server.

As of 0.4.2, you can also get Inject as a Bower package via bower install inject. Our Bower repository can be found here.

Adding Inject to Your Page

This walkthrough is assuming you're using a directory called js which contains all of your javascript, possibly even this file. It also assumes inside of the js directory is a modules directory which will contain all of your modules. Your directory layout might look like the following:

|-relay.html (optional)

The location of the modules directory does not need to be under the inject.js file, but it's common practice to group files of similar types together such as JavaScript.

Starting Your JavaScript

To use inject, place the following script tags into the <head> of your document

<script type="text/javascript" src="inject.js"></script>
<script type="text/javascript">
  • Inject.setModuleRoot is the location of ALL your JS modules. Based on the directory structure above, they are located in the js/modules directory.
  • executes your main entry point, whatever it may be. Given the above directory structure, it will run the program.js file in your module root (from require.setModuleRoot). The .js is added automatically.

Some Quick Configs

Here's some common configuration options you're going to want for Inject

// Set the "root" where all your modules can be found
// you can use an http:// path or just /path/to/modules like above

// Specify how long files should be in localStorage (in minutes)
// or 0 for never, which is great for development

// configure "cross domain" support. You need to put "relay.swf" and "relay.html"
// on your remote server for this to work
  relayHtml: "",

Writing Some Modules

When you're ready to write your own modules, have a look at the CommonJS Module Examples to get started.

Building From Source

We have a whole section on building from source. Building From Source has all the juicy details.

Next Steps

From here, you can...

On The Shoulders of Giants

Inject couldn't be as great as it is without these other rockstar libraries:

  • easyXDM: Cross Domain Communication
  • lscache: LocalStorage Cache Provider
  • link.js: dependency extraction (from their src/Library/link.js)
  • GoWithTheFlow.js: simple flow control
  • (and a whole lot of npm related things for development)