node package manager


Express middleware for optimizing and manipulating HTML pages and their related assets while serving them


Middleware that allows you to use AssetGraph to manipulate HTML pages and their related assets while they are being served.

Make sure you have node.js and npm installed, then run:

npm install assetgraph-middleware

An Express-based static file server that bundles JavaScript and CSS, inlines JavaScript, and assigns md5-derived urls to CSS, shortcut icons and background images:

var express = require('express'),
    root = '/path/to/static/files';

        root: root,
        transform: function (assetGraph, cb) {
                    followRelations: {
                        type: ['HtmlStyle', 'HtmlScript', 'CssImage', 'HtmlShortcutIcon'],
                        to: {
                            url: /^file:/
                .bundleRelations({type: ['HtmlStyle', 'HtmlScript']})
                .inlineRelations({type: 'HtmlScript'})
                .prettyPrintAssets({type: ['Html', 'JavaScript', 'Css']})
                .moveAssetsInOrder({type: assetGraph.constructor.query.not('Html')}, function (asset) {
                    return '/static/' + asset.md5Hex + asset.extension;

3-clause BSD license -- see the LICENSE file for details.