caching - Node.js/快速缓存

标签 caching google-chrome node.js express browser-cache

我是 Node.js/Express 的新手,但我想我正在慢慢掌握它。我添加了这段代码,据我所知这似乎是非常标准的:

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

浏览 Chrome 的缓存会发现,是的,一切都在缓存中。欢呼!但是当我在我的网站上运行 Chrome 的审核时(我注意到,在其他 Node 支持的网站上),Chrome 说该网站没有缓存任何东西。是什么导致了这种差异?

最佳答案

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);

执行上面的代码,然后导航到位于/public 目录中并具有测试图像的 test.html 页面,为我提供了以下响应 header ,并且 Chrome Audit 在我的 PC 上运行良好(Chrome 17.0.963.83,Linux, Node 0.6.13,Express 最新)。您应该仔细检查它是否真的处于生产模式。

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

关于caching - Node.js/快速缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470603/

相关文章:

google-chrome - Setcookie语法Google Chrome

html - CSS3 Perspective() 动画在鼠标快速移动时表现得很奇怪

javascript - 在运行时添加路由 (ExpressJs)

javascript - Heroku + Node : Cannot find module error

node.js - 当浏览器发出请求时,express 中间件函数被调用两次

ios - 如何使用 iPhone 应用程序缓存 Facebook 好友列表

html - 防止 Chrome 中的 iframe 缓存

javascript - 在旧的 chrome 版本上检测独立模式

php - 每 60 分钟解码并缓存 json

javascript - 本地存储中的安全浏览器端缓存