I have an Express 3.0 app and I'm trying to use the static()
, staticCache()
, and compress()
middleware to serve and compress my static files. This is my current app.configure()
function:
app.configure(function() {
app.use(express.favicon(__dirname + '/public/favicon.ico', {maxAge: 86400000}));
app.use(express.bodyParser());
app.use(express.cookieParser('foo'));
app.set('views', __dirname + '/views');
app.engine('.html', mustache({cache: true}).render);
app.use(express.session({ store: sessionStore, secret: 'foo'}));
app.use(express.staticCache());
app.use(express.static(__dirname + '/public', {maxAge: 86400000}));
app.use(express.compress());
});
// routes are loaded here
With this configuration, YSlow reports that my .css and .js files are not compressed and I can't get a cache hit without clearing my browser and refreshing the page multiple times. I also tried putting in a debug statement in the staticCache middleware to report cache hits and running ab -n 10000 -c 500 shows 0 cache hits.
Obviously I'm doing something wrong (I'm guessing the order or options are messed up) but I can't figure out what it is. Anybody have a working example with these three pieces of middleware working correctly together?