HTTP中缓存控制标头的最大值 [英] Max value for cache control header in HTTP

查看:156
本文介绍了HTTP中缓存控制标头的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Amazon S3为我的网站提供静态资源。我想让浏览器尽可能长时间地缓存这些资产。我应该在资产中包含哪些元数据标题

I'm using Amazon S3 to serve static assets for my website. I want to have browsers cache these assets for as long as possible. What meta-data headers should I include with my assets

Cache-Control: max-age=???


推荐答案

通常建议将一年作为标准最大值。请参阅 RFC 2616

Generally one year is advised as a standard max value. See RFC 2616:


要将响应标记为永不过期,原始服务器会在响应为
发送后约一年内发送
到期日期。 HTTP / 1.1服务器不应该在未来发送过期日期超过一个

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.

虽然这适用于较旧的到期标准,在没有任何明确的标准指导的情况下,适用于缓存控制也是有意义的。只要你通常需要它,并且选择任意更长的值可能会打破一些用户代理。所以:

Although that applies to the older expires standard, it makes sense to apply to cache-control too in the absence of any explicit standards guidance. It's as long as you should generally need anyway and picking any arbitrarily longer value could break some user-agents. So:

Cache-Control: max-age=31536000

这篇关于HTTP中缓存控制标头的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆