Cookies have two attributes (Max-Age
and Expires
) that seem to serve identical purposes, namely specifying when a given cookie will expire.
According to MDN, Expires
:
Indicates the maximum lifetime of the cookie as an HTTP-date timestamp. See Date for the required formatting.
And Max-Age
:
Indicates the number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
To me this sounds like they're completely synonymous, the only difference being the format in which the expiration date is expressed; with Expires
specifying an actual date-time, and Max-Age
specifying a time span.
It seems like Expires
actually predates Max-Age
, and Max-Age
was introduced much later, but why? That's my question. What shortcoming does Expires
have that Max-Age
looks to rectify? And when should one be preferred over the other? If the only thing that's different about Max-Age
is how it expresses the expiration date, then its introduction seems pretty pointless, doesn't it?
To my surprise, I couldn't actually find any relevant information on this, it seems as though I'm the only one for whom this is a question mark, which I find strange, so tell me if I'm missing something.
Note that my question isn't strictly about the technical difference between the two attributes (there are already questions like this one that cover this), I'm specifically curious about the reason and the motive behind the introduction of Max-Age
, when Expires
already existed and did fundamentally the same thing.