簡體   English   中英

如何在Amazon S3中使用瀏覽器緩存?

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

我在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文件指定瀏覽器緩存?

通過Amazon Management Console,選擇您的文件(或文件夾)。

在此輸入圖像描述


轉到“屬性”選項卡,然后單擊“元數據”。

在此輸入圖像描述


最后,將Cache-Control添加到其標頭並保存。

在此輸入圖像描述

您可以使用s3cmd指定header參數! 在將文件上傳到s3時。

例如:

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

將文件存儲到s3時。 您可以設置將發送到客戶端的自定義標頭。 在這種情況下,您可以為文件設置Expires標頭。

Cloudfront的工作方式略有不同,因為它取決於您的來源。

我對這個問題很幸運。 實際上,在Bucket中上傳文件時,您應該會在上傳窗口中看到SET DETAILS

單擊它並完成它。 您最終會為文件選擇SET METADATA

還有其他方法。 這可能對你有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM