简体   繁体   English

如何在Amazon S3中使用浏览器缓存?

[英]How to use browser caching with Amazon S3?

I get the following on gtmetrix.com: 我在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)

I'm guessing the mailchimp files can't be modified. 我猜测mailchimp文件无法修改。 But how do I specify a browser cache for Amazon S3 Cloudfront files? 但是,如何为Amazon S3 Cloudfront文件指定浏览器缓存?

Via Amazon Management Console, select your file (or folder). 通过Amazon Management Console,选择您的文件(或文件夹)。

在此输入图像描述


Go to the Properties tab and click on Metadata. 转到“属性”选项卡,然后单击“元数据”。

在此输入图像描述


Finally, add Cache-Control to its header and save. 最后,将Cache-Control添加到其标头并保存。

在此输入图像描述

You can specify header parameter with the s3cmd ! 您可以使用s3cmd指定header参数! while uploading files to s3. 在将文件上传到s3时。

eg : 例如:

s3cmd sync LOCAL_DIRECTORY s3://BUCKET[/PREFIX] --add-header=Cache-Control:max-age=3153600

When you store files to s3. 将文件存储到s3时。 You can set custom headers which will be send to the client. 您可以设置将发送到客户端的自定义标头。 In this case, you can set an Expires header for your files. 在这种情况下,您可以为文件设置Expires标头。

Cloudfront works a little bit differently as it depends on your origin. Cloudfront的工作方式略有不同,因为它取决于您的来源。

I just got lucky with this question. 我对这个问题很幸运。 Actually, when uploading files in Bucket you should see SET DETAILS in the upload window. 实际上,在Bucket中上传文件时,您应该会在上传窗口中看到SET DETAILS

Click it and go through it. 单击它并完成它。 You'd end up with an option to SET METADATA for the files. 您最终会为文件选择SET METADATA

There are other ways too. 还有其他方法。 This might help you. 这可能对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM