我花了一个多小时试图在生产中快速缓存静态文件。有什么我做错了吗?所有标头在第一个请求中返回 200,在后续请求中返回 304。我什至尝试将代码粘贴到主 app.configure 中,并直接从 express 文档中粘贴代码。
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) {
.......