This is a simple combo handler for Node.js, usable either as Connect
middleware or as an Express server. It works just like the combo handler
service on the Yahoo! CDN, which you'll be familiar with if you've used YUI.

The combo handler is compatible with the YUI Loader, so you can use it to
host YUI, or you can use it with any other JavaScript or CSS if you're willing
to construct the combo URLs yourself.

The combo handler itself doesn't perform any caching or compression, but stick
Nginx or something in front of it and you should be ready to rock in
production.

The respond method exported by require('combohandler') is a convenience
method intended to be the last callback passed to an
express route.
Unless you have a very good reason to avoid it, you should probably use it.
Here is the equivalent callback:

functionrespond(req, res){

res.send(res.body);

}

This method may be extended in the future to do fancy things with optional
combohandler middleware.

If you just want to get a server up and running quickly by specifying a mapping
of routes to local root paths, use the combohandler/lib/server module.
It creates a barebones Express server that will perform combo handling on the
routes you specify:

If installed globally via npm -g install,
the CLI executable combohandler is provided.
If you're operating from a local clone,
npm link in the repository root and you're off to the races.
To start the default single-process server,
it's as simple as

combohandler

# combohandler now running until you hit Ctrl+C

Of course, the default output leaves something to be desired: that is to say,
any output.

Because the combo handler changes the path from which CSS files are loaded,
relative URLs in CSS files need to be updated to be relative to the
combohandled path.
Set the basePath or webRoot configuration option to have the
combohandler default middleware do this automatically.

// This static route can be used to load images and other assets that shouldn't

// be combined.

//

app.use('/public', express.static(__dirname+'/public'));

// This route will combine requests for files in the public directory, and will

// also automatically rewrite relative paths in CSS files to point to the

// non-combohandled static route defined above.

//

app.get('/combo', combo.combine({

rootPath:__dirname+'/public',

basePath:'/public'

}), combo.respond);

// The equivalent config as the previous route, except using webRoot

app.get('/combo', combo.combine({

rootPath:__dirname+'/public',

webRoot :__dirname

}), combo.respond);

Alternatively, you can use the built-in cssUrls middleware as a separate
route callback. cssUrls must always be placed after the default combine
middleware when used in this fashion.

// This route provides the same behaviour as the previous example, providing

// better separation of concerns and the possibility of inserting custom

// middleware between the built-in steps.

app.get('/combo',

combo.combine({

rootPath:__dirname+'/public'

}),

combo.cssUrls({

basePath:'/public'

}),

combo.respond);

Finally, the cssUrls middleware has the ability (disabled by default) to
rewrite @import paths in the same manner as url() values. As @import is
considered an anti-pattern in production code, this functionality is strictly
opt-in and requires passing true as the rewriteImports property in the
middleware options object.

In the simplest case,
basePath and webRoot reach the same result from different directions.
basePath allows you to rewrite a single well-known path under any root,
whereas webRoot will handle any number of paths under a well-known root.

In general, if you are using both optional middleware,
you should prefer webRoot over basePath.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.