Amazon S3: Cache-Control and Expiry Date difference and setting trough REST API

后端 未结 3 755
Happy的楠姐
Happy的楠姐 2020-12-31 20:45

I want to enhance my sites loading speed, so I use http://gtmetrix.com/, to check what I could improve. One of the lowest rating I get for \"Leverage browser caching\". I fo

3条回答
  •  情话喂你
    2020-12-31 21:42

    S3 lets you specify the max-age and Expires header for cache control , CloudFront lets you specify the Minimum TTL, Maximum TTL, and Default TTL for a cache behavior. and these header just tell when will the validity of an object expires in the cache(be it cloudfront or browser cache) to read how they are related read the following link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist

    For letting you Leverage Browser caching just specify the Cache control header for all the object on s3 do Steps for adding cache control for existing objects in your bucket

    1. git clone https://github.com/s3tools/s3cmd
    2. Run s3cmd --configure (You will be asked for the two keys - copy and paste them from your confirmation email or from your Amazon account page. Be careful when copying them! They are case sensitive and must be entered accurately or you'll keep getting errors about invalid signatures or similar. Remember to add s3:ListAllMyBuckets permissions to the keys or you will get an AccessDenied error while testing access.)
    3. ./s3cmd --recursive modify --add-header="Cache-Control:public ,max-age= 31536000" s3://your_bucket_name/

提交回复
热议问题