CloudFront 图像缓存控制标头

发布于 2024-11-29 17:48:31 字数 325 浏览 3 评论 0原文

1- 这是一个有效的缓存控制标头吗:

Cache-Control: max-age=86400, s-maxage=3600

2- 我正在尝试为通过 CloudFront 从 S3 提供服务的对象设置缓存控制标头。图像不会经常改变,但有时会改变。这看起来是一个很好的缓存控制吗? CloudFront 应每 60 分钟重新验证一次,但用户将缓存一整天。 (我不太担心单个用户,更担心继续向新用户提供过时的图像)。

3-我还应该使用其他标头吗? (即代理重新验证)

更改 S3 对象上的这些设置并不容易,因此我试图第一次就正确。谢谢。

1- Is this a valid cache control header:

Cache-Control: max-age=86400, s-maxage=3600

2- I am trying to set cache control headers for objects served from S3 through CloudFront. The images don't often change, but sometimes can. Does this seem like a good cache control for this? CloudFront should re-validate every 60 minutes, but the user will cache for a full day. (I'm less worried about an individual user and more worried about continuing to serve the stale image to new users).

3- Are there other headers I should use? (ie. proxy-revalidate)

Its not horrendously easy to change these settings on S3 objects so I'm trying to get it right the first time. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光病人 2024-12-06 17:48:31

我刚刚让它与

  1. Access-control-Max-Age (在 S3 COR 设置中设置)
  2. 一起使用缓存控制
  3. 过期

理论上,从 AWS S3 / Cloudfront 文档来看,只有 1. 有效。在实践中,两者都需要。

基思

I just made it working with both

  1. Access-control-Max-Age (Set in S3 CORs setting)
  2. Cache-control
  3. expires

In theory and from AWS S3 / Cloudfront doc, only 1. will works. In practice, it takes both.

Keith

风渺 2024-12-06 17:48:31

这就是我要做的工作:

Cache-Control: max-age=29030400, public
Expires: Wed, 30 Dec 2015 18:00:00 GMT

理论上,你只需要其中之一。但是 S3 和 CloudFront 的整个浏览器缓存一直是我的一大痛苦,所以我喜欢将它们都保留在那里。我还将以下内容放入我的 .htaccess 文件中:

# BEGIN Caching
Header set Cache-Control "max-age=29030400, public"
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/plain "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END Caching

Here's what I got to work:

Cache-Control: max-age=29030400, public
Expires: Wed, 30 Dec 2015 18:00:00 GMT

In theory, you only need one or the other. But this whole browser caching thing with S3 and CloudFront has been a big pain in my backside, so I like to keep them both in there. And I also put the following in my .htaccess file:

# BEGIN Caching
Header set Cache-Control "max-age=29030400, public"
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/plain "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END Caching
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文