The main point is that we need to understand a relative (expires) and an absolute (max-age ).
Respectively
Max-age
In HTTP/1.1, Max-age refers to the survival time of files in our web environment after being accessed (requested) by users. It is a relative value, relative request_time (request time ).
For example, if the.html user request time is and the max-age value is 600, it will expire after + 600 seconds, that is, it will expire after 600 seconds after. the default max-age is calculated by expires.
Expires
Expires is in HTTP/1.0, which is more troublesome than Max-age. The time specified by expires is divided into the following two types, which mainly takes into account whether to set a or m in Apache.
1.Relative file last access time (atime)
When Apache uses a time for expires, the value of max-age is equal to that of max-age, because Max-age is relative to the request time of the file (atime ).
Example: expiresbytype text/html a600
We learned from the above that When apache sets atime, the expiration time is 600 seconds.
Expires = + 600 =
Max-age = + 600 =
Obtained: expires = max-age
2. Absolute modification time (mtime)
Let's talk about a.htm.
Assume that the file is created.
When the user's request is, the expiration time is 600 seconds.
Expires = + 600 =
Max-age = + 600 =
It is concluded that expires is equal to max-age.
When the user's request is, the expiration time is 600 seconds.
Expires = + 600 = (because when set to mtime, the time is determined by the File Creation Time)
Max-age = + 600 =
It is concluded that expires is not equal to max-age.
In addition, it should be noted that the max-age is optimized when the above conditions are cleared, so the expiration time is.
In squid, if the expiration time of expires and max-age is not specified, it will use the expiration time. For example, see last-modified.
In fact, the above max-age = + 600 =, so that the max-age is incorrect. in the real environment, the max-age expires in the HTTP header and the age = 600 expires.
Note: The age field value is the total time that the cache server has estimated since the response was generated or re-confirmed by the original server. The age value is calculated by the cache server and does not exist on the original server.
HTTP max-age and expires