【发布时间】:2017-09-30 03:02:09
【问题描述】:
我正在使用静态内容插件维护 Restify 服务器。尽管事先发生了任何事情,该插件都会强制使用 Cache-Control 标头。 max-age 始终包含在内,默认为 3600。
Cache-Control: public, max-age=3600
除了index.html之外的所有东西我都需要一个大的max-age。
server.pre((req, res, next) => {
const path = url.parse(req.url);
if (path.pathname === '/' && req.accepts('text/html')) {
req.url = '/public/index.html';
// Encourage the client to always download index.html.
res.header('Expires', '0');
res.header('Cache-Control',
'no-store, no-cache, must-revalidate, max-age=0');
}
next();
});
问题是静态服务器强制添加Cache-Control导致服务器发送矛盾的max-age值。
Cache-Control:no-store, no-cache, must-revalidate, max-age=0
Cache-Control:public, max-age=315360000
我尝试了一些方法来阻止它,但它不起作用,但这甚至是一个问题吗?不知道浏览器会不会通过下载index.htmlfresh来解决矛盾(这是我想要的)
【问题讨论】:
标签: javascript node.js http caching restify