3 ms·
Use unique IP addresses for sharded asset hosts
- byoung2 16y agoI use Amazon Cloudfront to host assets, and this problem is taken care of for me. I created an S3 container to store all of the files (in this case thousands of images). Then I created a Cloudfront distribution to serve them over a CDN. Cloudfront lets you create multiple CNAMEs per distribution so I created a CNAME for images1.domain.com through images10.domain.com to my distribution. In my app I created a simple hashing algorithm to assign the right subdomain (basically it takes an MD5 of the filename, looks at the second character, converts hex to dec and that is the number of the subdomain). That way any given image gets served from the same subdomain to take advantage of caching. And the bonus is that Cloudfront assigns each of the CNAMEs a different IP address.