8 ms·
One big warning here. If you are wanting to serve static content for multiple domains (e.g. somefont.ttf for foo.example.com, bar.example.com and baz.example.c
by mattdeboard 13y ago
One big warning here.
If you are wanting to serve static content for multiple domains (e.g. somefont.ttf for foo.example.com, bar.example.com and baz.example.com from a single CloudFront distribution) CloudFront is not your solution, because CloudFront does not vary its cache on the Origin header. So if your first visitor is loading foo.example.com/static/fonts/somefont.ttf, then the Access-Control-Allow-Origin header for somefont.ttf will be set to "foo.example.com". Subsequent requests for that file from (bar|baz).example.com will fail with a CORS error.
It was a pretty shocking thing to find out. We've concluded AWS/CloudFront isn't a viable CDN until this is fixed. Based on the following thread, it isn't clear when or if it will be fixed: https://forums.aws.amazon.com/thread.jspa?threadID=114646# https://forums.aws.amazon.com/thread.jspa?threadID=114646#
- prostoalex 13y agoAny reason to serve this from a single distribution? Their UI basically tells you in no uncertain terms that subdomain == distribution.
- mattdeboard 13y agoWhere does it say that? I'm not talking about assigning foo.example.com as the domain name for the distribution.
- prostoalex 13y agoRight, this is still the scenario where you're using the distribution hostname they give you, e.g. abcdef1234.cloudfront.net http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/WorkingWithDownloadDistributions.html#DownloadDistValuesDomainName http://docs.aws.amazon.com/AmazonCloudFront/latest/Developer... "Changing the origin does not require CloudFront to repopulate edge caches with objects from the new origin. As long as the viewer requests in your application have not changed, CloudFront will continue to serve objects that are already in an edge cache until the TTL on each object expires or until seldom-requested objects are evicted."