Reputation: 2209
I m trying to leverage browser caching for my website in order to please "google page speed check".
google complains that there is NO expiration date defined in my images so I m trying to add a "cache-control" header
to my images. I m serving the images via Amazon cloudfront
and the origin is S3
. I read several articles and the steps I m following are:
s3
bucket and manually set a "cache-control" header
for my test object (image). I works and I can see the header in my browser.I go to my CloudFront distribution, "behaviour" -> "edit"
and
from there I ve tried the following things:
a) set "Forward Headers" to "all"
. Amazon complains that "all"
value
cannot be set when origin is s3
.
b) set "Forward Headers" to "Whitelist"
-> Add "Origin"
as
whitelisted header. It doesnt work. When I check my browser I dont
see the "cache-control" header
c) set "Forward Headers" to "None"
-> and "Object Caching"
to "Use
Origin Cache Headers". It doesnt work.
d) set "Forward Headers"
to "None"
-> and "Object Caching
" to
"Cusomize"
-> Specify a value for min/max/default TTL . It doesnt
work.
So I ran out of options and hope. Any ideas how can I achieve letting CloudFront
forward the headers to the browser?
Upvotes: 1
Views: 4329
Reputation: 1324
The issue is that you're not waiting for the changes to propagate. I have been using the below configurations successfully.
Post this, just wait for the changes to propagate. (if you're so impatient, then create a *
invalidation)
To upload assets, you can use the following command [Assuming that you have aws cli downloaded].
aws s3 sync local_dir s3://bucket --cache-control max-age=604800
Upvotes: 2