Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何在AmazonS3中使用浏览器缓存?_Amazon Web Services_Amazon S3_Amazon Cloudfront - Fatal编程技术网

Amazon web services 如何在AmazonS3中使用浏览器缓存?

Amazon web services 如何在AmazonS3中使用浏览器缓存?,amazon-web-services,amazon-s3,amazon-cloudfront,Amazon Web Services,Amazon S3,Amazon Cloudfront,我在gtmetrix.com上获得以下信息: Leverage browser caching E (55) 52% Server High What does this mean? The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources: ht

我在gtmetrix.com上获得以下信息:

Leverage browser caching    
E (55)
52%
Server  High
What does this mean?
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

http://mysite.s3.amazonaws.com/profile.png (expiration not specified)
http://mysite.s3.amazonaws.com/circle.player.css (expiration not specified)
http://mysite.s3.amazonaws.com/main.js (expiration not specified)
http://mysite.s3.amazonaws.com/not.the.skin.css (expiration not specified)
http://cdn-images.mailchimp.com/embedcode/slim-321711.css (expiration not specified)

我猜mailchimp文件无法修改。但是如何为Amazon S3 Cloudfront文件指定浏览器缓存呢?

当您将文件存储到S3时。您可以设置将发送到客户端的自定义头。在这种情况下,可以为文件设置Expires头


Cloudfront的工作原理稍有不同,因为它取决于您的来源。

您可以使用!当上传文件到s3时

例如:

通过Amazon管理控制台,选择您的文件(或文件夹)。


转到属性选项卡并单击元数据。


最后,将缓存控件添加到其标头并保存。

有两个控制台:S3管理控制台和Cloudfront控制台。你能说出其中一个标题是如何设置的吗?我看不到标题信息的任何位置。对于s3文件,您可以为每个要更新的文件转到属性->元数据部分。Cloudfront从源站获取标题。谢谢。有没有关于应该使用什么键/值来控制浏览缓存的例子?有几个例子可以看一下
Expires
有一个日期,通常是一个遥远的未来日期。但是,如果进行更改,则可能需要对文件名进行版本设置。否则,返回的用户可能会保留旧版本。要查看的其他标题是
缓存控制
上次手动修改
?逐一地?如果你有数千个文件呢?如果您想更新这些值,该怎么办?值得一提的是,这也可以使用:
aws s3 sync$LOCAL s3://$REMOTE--cache control“max age=3153600”
手动进行?逐一地?如果你有数千个文件呢?如果您想更新这些值怎么办?那么您一定要使用AWS CLI:您可以将其添加到bucket中的整个文件夹中,它将更新所有包含的对象。不要忘记也添加
Expires
headerExpires头,如果设置了max age,则忽略该头。资料来源:
s3cmd sync LOCAL_DIRECTORY s3://BUCKET[/PREFIX] --add-header=Cache-Control:max-age=3153600