Create external Browserify bundles for lazy asynchronous loading
JavaScript CoffeeScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test Add failing test for transforms Apr 14, 2013
.travis.yml Add Travis-CI Apr 7, 2013
LICENSE Add license Apr 14, 2013
package.json Release 0.1.1 Apr 15, 2013

This module is not maintained anymore. Please try substack/factor-bundle instead

build status


Create external Browserify bundles for lazy asynchronous loading

Introduction to asynchronous module loading with Browserify:


npm install externalize


The module exports a single function

    <parent bundle or array of parent bundles>,
    <bundle or arrays of bundles to be externalized from the parent bundles>,
    <callback function>


Create two bundles where the second one is a subset of the parent and call externalize(parent, subset, callback) on them. It will do following:

  1. Moves all modules that are used in both to the parent one
  2. Removes those modules from the parent one that are explicitly requireable in the subset one
  3. It generally tries to do the "right thing"

in code:

var fs = require("fs");
var browserify = require("browserify");
var externalize = require("externalize");

// Parent bundle with an entry point
var parent = browserify("./index.js");

// Make subset bundle from external.js by making it explicitly requireable
var subset = browserify().require("./external.js");

// Remove the subset bundle code from the parent
externalize(parent, subset, function(err) {
    if (err) throw err;

    // Write bundles to files after externalization


// require("./external");
// Would not work here because external.js is externalized to the subset bundle

// Use any script loader to load the subset bundle to make the require work
// again
jQuery.getScript("bundle/subset.js", function(){
    var value = require("./external");
    // Alerts: "external module: external module contents"
    alert("external module: " + value);


module.exports = "external module contents";

Script loaders

You need a script loader to load the external bundles. There is one in jQuery. If you don't use jQuery you can grab $script.js from npm or implement your own for modern browsers easily.

Some others include: