缓存控制中 max-age=0 和 max-age=-1 有什么区别?

Vla*_*kyi 4 caching http cache-control max-age

Cache-control: max-age=0两个 header和之间的浏览器行为有什么区别Cache-control: max-age=-1

如果浏览器收到 max-age=0,它将立即重新验证缓存。如果浏览器收到 max-age=10,它将在 10 秒后重新验证缓存。max-age=-1 时浏览器的行为是什么?和 max-age=0 一样吗?如果是,为什么我们需要两者?

Joe*_*Joe 6

max-age接受一个匹配的参数delta-seconds

The delta-seconds rule specifies a non-negative integer, representing
time in seconds.

  delta-seconds  = 1*DIGIT
Run Code Online (Sandbox Code Playgroud)

max-age=-1因此不是有效的指令,并且规范没有定义解释。该规范建议:

Caches are
encouraged to consider responses that have invalid freshness
information to be stale.
Run Code Online (Sandbox Code Playgroud)