我正在尝试将标题添加到我在Sails.js中传输到客户端的图像中。为此,我创建了一个在输出图像文件之前运行的策略。
module.exports = function (req, res, next) {
res.writeHead(200, {
"Cache-Control": "private, max-age=200",
"Expires": "SOME EXPIRY DATE"
});
next();
};
我的回复标题已更改,如下所示:
HTTP/1.1 200 OK
X-Powered-By: Sails <sailsjs.org>
Access-Control-Allow-Origin:
Access-Control-Allow-Credentials:
Access-Control-Allow-Methods:
Access-Control-Allow-Headers:
Cache-Control: private, max-age=200
Expires: Sun Oct 12 2014 23:18:39 GMT
Date: Sat, 11 Oct 2014 17:33:39 GMT
Connection: keep-alive
Transfer-Encoding: chunked
然而,当我再次加载页面时,浏览器似乎再次请求图像。我在这里缺少什么?
答案 0 :(得分:0)
将此添加到config / http.js
的底部module.exports.cache = {
// The number of seconds to cache files being served from disk
maxAge: 86400000 // millsec = 24 hours
};