Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 828
JacobEvelyn Avatar asked Feb 27 '12 18:02

JacobEvelyn


1 Answers

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
like image 189
Mustafa Avatar answered Sep 21 '22 04:09

Mustafa