2007年8月9日星期四

过期时间设置 expires and max-age (一)

最近对关于http协议的rfc都或多或少的看了些!
随便也看了关于expires vs max-age
关于http/1.1协议的rfc2616上有这么三句话很有意思。
HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").

To mark a response as "already expired," an origin server sends an Expires date that is equal to the Date header value. (See the rules for expiration calculations in section 13.2.4.)

To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time the response is sent. HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future.

The presence of an Expires header field with a date value of some time in the future on a response that otherwise would by default be non-cacheable indicates that the response is cacheable, unless indicated otherwise by a Cache-Control header field (section 14.9).

上面提到什么是过期:expires date ==date header
什么是不过期:expires date > date header
也提到了我们现在通常处理使得 expires date= 0 或者 expires date < date header
在这种非标准的header下面,http/1.1协议是怎么去解释的!
基本上没有设置expires date 就应该默认不能被cache,除非有section 14.9中其他的cache-control.
关于max-age 只想提这么一句话:
If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive

也就是max-age会优先expires!
在过期时间设置 expires and max-age (二)将抛开协议本身,来详细了解下在apache.lighttpd中怎么样去定制一个有比较好的过期时间设置的header

没有评论: