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

时间:2022-11-19 09:23:05

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. But how do I specify a browser cache for Amazon S3 Cloudfront files?

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

4 个解决方案

#1


5  

When you store files to 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.

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

Cloudfront works a little bit differently as it depends on your origin.

Cloudfront的工作方式略有不同,因为它取决于您的来源。

#2


17  

Via Amazon Management Console, select your file (or folder).

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


Go to the Properties tab and click on Metadata.

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


Finally, add Cache-Control to its header and save.

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

#3


10  

You can specify header parameter with the s3cmd! while uploading files to s3.

您可以使用s3cmd指定header参数!在将文件上传到s3时。

eg :

例如:

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

#4


0  

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.

还有其他方法。这可能对你有帮助。

#1


5  

When you store files to 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.

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

Cloudfront works a little bit differently as it depends on your origin.

Cloudfront的工作方式略有不同,因为它取决于您的来源。

#2


17  

Via Amazon Management Console, select your file (or folder).

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


Go to the Properties tab and click on Metadata.

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


Finally, add Cache-Control to its header and save.

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

#3


10  

You can specify header parameter with the s3cmd! while uploading files to s3.

您可以使用s3cmd指定header参数!在将文件上传到s3时。

eg :

例如:

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

#4


0  

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.

还有其他方法。这可能对你有帮助。