httpcachingcache-controlmax-age

What is the difference between max-age=0 and max-age=-1 in Cache Control?


What's the difference in browser behavior between two headers Cache-control: max-age=0 and Cache-control: max-age=-1?

If the browser receives max-age=0, it will revalidate cache immediately. If the browser receives max-age=10, it will revalidate cache after 10 seconds. What's browser behavior with max-age=-1? Is it the same like with max-age=0? If yes, why we need both?


Solution

  • max-age takes an argument that matches delta-seconds:

    The delta-seconds rule specifies a non-negative integer, representing
    time in seconds.
    
      delta-seconds  = 1*DIGIT
    

    max-age=-1 is therefore not a valid directive, and the specification doesn't define an interpretation. The spec suggests:

    Caches are
    encouraged to consider responses that have invalid freshness
    information to be stale.