The difference between expires and Max-age

Source: Internet
Author: User

Both expires and max-age can be used to specify the expiration time of a document, but there are some minor differences

1.Expires has been defined in the http/1.0, cache-control:max-age in http/1.1 is defined, in order to backward compatibility, only use max-age enough;
2.Expires specifies an absolute expiration time (GMT format), which results in at least 2 issues 1) client and server time synchronization causes problems with configuration of expires 2) it is easy to forget the specific expiration time after the configuration, resulting in the arrival of the expiration of a surge phenomenon;

3.max-age specifies the time to live after the document has been accessed, which is a relative value (for example, 3600s), relative to the Request_time (Request time) recorded by the server the first time the document was requested.

The time specified by 4.Expires can be relative to the last access time (Atime) or modification time (MTime) of the file, whereas Max-age is relative to the document's request time (Atime)

5. In Apache, Max-age is calculated based on expires time Max-age = Expires-request_time: (MOD_EXPIRES.C)

429 expires = base + additional;
430 Apr_table_mergen (T, "Cache-control",
431 apr_psprintf (R->pool, "max-age=%" apr_time_t_fmt,
432 apr_time_sec (Expires-r->request_time)));

Note: If it is a,base=request_time,m words base=finfo.mtime.
Expires-request_time Get Max-age, if expires is based on a (that is, accesstime) set (the value after a is addtional), then the value of expires set is equal to the addtional value, But if expires is based on Mtime, then if the parameter behind M is less than the difference from the last modification time to the current time (say 2 hours ago, the file was modified (19:00:00), now set M3600 (now 21:00:00) and access, max-age= Expires-request_time = (finfo.mtime+additional)-request_time), the calculated max-age is a negative number (you can experiment to see this result):
Max-age = (19:00:00+3600/3600)-21:00:00 = -3600s

Thus, in Apache, Max-age is not just a relative atime time, if set to M, the relative is mtime.

The difference between expires and Max-age

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.