JacobEvelyn
JacobEvelyn

Reputation: 3971

Node.js/Express Caching

I'm pretty new to Node.js/Express, but I think I'm slowly getting the hang of it. I've added this code, which from what I can tell seems to be pretty standard:

app.configure('production', function() {
    var oneYear = 31557600000;
    app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
    app.use(express.errorHandler());
});

A peek into Chrome's cache reveals that, yes, everything is caching. Hurray! But when I run Chrome's audits on my site (and, I've noticed, on other Node-powered sites), Chrome says that the site isn't caching anything. What could cause this discrepancy?

Upvotes: 7

Views: 7698

Answers (1)

Mustafa
Mustafa

Reputation: 10413

var express = require('express');
var app = express.createServer();
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
app.get('/', function(req, res){
  res.send('hello world');
});
app.listen(3000);

Executing the code above, and navigating to a test.html page which lies in /public directory and has a test image gives me the following response headers and Chrome Audit is just fine on my PC (Chrome 17.0.963.83, Linux, Node 0.6.13, Express latest). You should double check if it is really in production mode.

Accept-Ranges:bytes
Cache-Control:public, max-age=31557600
Connection:keep-alive
Date:Fri, 23 Mar 2012 22:52:24 GMT
ETag:"120877-1278958150000"
Last-Modified:Mon, 12 Jul 2010 18:09:10 GMT
X-Powered-By:Express

Upvotes: 10

Related Questions