Reputation: 1731
I've spent over an hour trying to get express to cache static files in production. Is there something i'm doing wrong? All of the headers come back 200 on the first request and 304 on subsequent requests. I've even tried pasting the code into the main app.configure and pasted code straight from the express documentation.
Request URL:http://localhost:3000/javascripts/jquery.min.js
Request Method:GET
Status Code:304 Not Modified
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Cache-Control:max-age=0
// Generated by CoffeeScript 1.3.3
(function() {
var app, express, fs, http, path;
express = require('express');
http = require('http');
path = require('path');
fs = require('fs');
app = express();
app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compress());
return app.use(require('less-middleware')({
src: __dirname + '/public'
}));
});
app.configure('development', function() {
app.use(express["static"](__dirname + '/public'));
app.use(app.router);
app.use(express.errorHandler());
return console.log("Hello from dev");
});
app.configure('production', function() {
app.use(express["static"](__dirname + '/public', {maxAge: 1800}));
app.use(app.router);
return console.log("Hello from prod");
});
app.get('/', function(req, res) {
.......
Upvotes: 2
Views: 4497
Reputation: 203359
maxAge
is a value in milliseconds, which in your case seems quite low (1800, which is 1.8s). The resources might be expiring from the cache before you even get the chance of reloading them, so they would seem to never get cached.
Upvotes: 4