Skip to content
Dropin require polyfill for the browser
JavaScript Other
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Brings exact CommonJS (require, exports) functionality to the Browser.

It has three parts:

1) A simple compiler that wraps your files in a closure that injects bound of require and exports, so you can use the exact same code client side.

2) A client side library that provides a require keyword

3) An optional clientside asynchronous require module


npm install brequire


Create a an instance of the compiler with require("brequire").module("path/to/my/module")

The various options can then be set via method calls:

  • .search(path, /* path2, path3 etc... /) set the search paths for the scripts to load from the root. (defaults to '*.js')

  • .write(path)

wraps each file writes it to disk. if path ends with '.js': the files will all be bundled together into one script. otherwise path is assumed to be a directory and each file will be written out separately, the structure mirroring the src directory

  • .module_base(name) us this method to change the module base name

  • .inspect() output the current state of the compiler including the files to be processed (for debugging purposes)

Example Usage

var brequire = require("brequire")


Include in your page

<script src='browser/require.js'></script>
<script src='my/module.js''></script>
var app = require("./app")
// do stuff with app

Async module

require.async.js is an optional module that hooks into require and provides an asynchronous require that loads modules via xhr. It also determines dependencies via static analysis and they are loaded in parallel.

Note that require.async will autowrap the module - so there's no need for the server side compilation step.

Use like:

<script src='browser/require.js'></script>
<script src='my/module.js''></script>
require("./app", function(app) {
  // do stuff with app  

See example in browser/test/index.html


  • require.async uses a regex to determine dependencies, which is solid with one caveats:

    • dynamic calls to require will not be picked up, e.g. require(myvar)
  • NB require's inside comments are not picked up

  • require.async works seemlessly with require, so if a dependency is already available, require.async will return immediately with no xhr

  • CoffeeScript lovers:

    • if you want to be able to do require.async("./") then just add the following line after coffeescript.js
    • require.registerExtension('.coffee', CoffeeScript.compile)


npm install should glob expresso

Something went wrong with that request. Please try again.