Recommend this page to a friend!
  Classes of Gamaiel Zavala  >  cmbn  >  >  Download  
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: cmbn
Generate combos of JavaScript code served via CDNs
Author: By
Last change: Update of
Date: 2 months ago
Size: 3,898 bytes


Class file image Download
# cmbn

Several public CDNs host popular JS libs, most notably [](
Until now there was no easy way to combo the various libs into a single URL in order to maximize
performance. This package fills that gap by generating and serving combo URLs across
various CDNs and any other public server.

## Install

    $ npm i cmbn

## Usage

This software is currently demoed at but there are no guarantees to availability.
It's recommended to install cmbn on your own host in order to enable comboing with application-specific assets.
To maximize performance even further cmbn should be fronted by a CDN like [CloudFlare](

### Standalone server

    var cmbn = require('cmbn');

##### Options

In addition to the options available for `middleware` ,`createServer` accepts one or more of the following:

* `port` - Port to listen on. Default is 80.
* `staticDir` - Directory to serve static assets from. Particularly useful if comboing from localhost.
* `staticMaxAge` - Number of seconds to set for `max-age` in the `Cache-Control` header if serving local assets.

### Middleware

    var connect = require('connect'),
        express = require('express'),
        cmbn = require('cmbn'),
        app = express.createServer();

##### Options

`middleware` takes an optional argument which is an object containing one or more of the following:

* `cacheSize` - The size in bytes to reserve for [lru-cache]( which stores fetched assets. Default is `5000000` (~5MB).
* `cacheFunc` - The cache function used to determine the size of each asset, default is to return `asset.length`.

### Node Client

    var cmbn = require('cmbn'),
        url = cmbn.client.combine([

##### Options

`combine` also takes an optional argument which is an object containing one or more of the following:

* `host` - The hostname[:port] which is running cmbn. Defaults to (see note under Usage). 
* `protocol` - The protocol for the host running cmbn. Defaults to `http`.

### Browser Client

    <script src=""></script>
    var url = cmbn.client.combine([

##### Options

See Node Client.

### Adding a CDN

    var cmbn = require('cmbn');
    // add cdn for localhost
    cmbn.cdns.addCdn('lh', {host: 'localhost:8080', prefix: 'libs/'});
    var url = cmbn.client.combine([
    ], {host: 'localhost:8080'});
    // http://localhost:8080/~gg;jquery,1.7.2,jquery.min.js/~lh;cmbn,0.0.1,cmbn.min.js

### Run the Example

After installing the package run `node examples` from the package root.
A link will be output by the client and the server will start.
Copy the link and paste it into a browser to see the comboed output.

### More

See the examples folder and code for more usage information.

## License

MIT License. See the accompanying LICENSE file for terms.