【问题标题】:Resolving contradictory Cache-Control headers解决矛盾的 Cache-Control 标头
【发布时间】: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


    【解决方案1】:

    引用Michael Krebs:

    我相信 max-age=0 只是告诉缓存(和用户代理)响应从一开始就是陈旧的,因此他们应该在使用缓存之前重新验证响应(例如使用 If-Not-Modified 标头)副本,而 no-cache 告诉他们必须在使用缓存副本之前重新验证。 From 14.9.1 What is Cacheable [...]

    为了简洁起见,这句话有点脱离上下文,但规范的语言使max-age 比no-cache、must-revalidate 等“弱”指令。实际行为仍然是浏览器中的实现细节,但是,如果max-age 出现在强烈告诉浏览器重新验证或不缓存的指令附近,那么预期浏览器将遵守 (Corroborating answer) 应该是合理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-23
      • 2015-04-13
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多