Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have my website assets stored on Amazon S3 and served by CloudFront, from a separate domain name, to act as a cookie-less domain (so website.com for the website and websitestatic.com for static assets). I set a far ahead Expires header, so they can be cached by the browser.

Google PageSpeed recommends: Parallelize downloads across hostnames. I can achieve this by adding subdomains pointing to the same CloudFront distribution and then randomize the URL to my assets, so I can have media1.websitestatic.com, media2.websitestatic.com, media3.websitestatic.com.

My question is, will browsers recognize individual files as being the same as pre-cached ones, if they are served from different subdomains? As media1, media2, etc...all serve the same files, if over two page requests the same image was served from media1 first, then media2 next, will a browser recognize this or will it download it again?

I can randomize the subdomain URL in the HTML files that serves the file (media1, media4, media8, etc...) but I can't store this random number for any particular file so that it is served from the same subdomain every time.

I'm guessing the answer is no, they won't, so if I was to implement random subdomains, I'd negate the advantage of having a cached version, as theoretically every page request you could get a different subdomain for the same file.

share|improve this question
2  
I'd recommend not adding too many hostnames, otherwise you hit the separate problem of too many hostname lookups. –  DisgruntledGoat Feb 9 at 19:09
add comment

1 Answer

up vote 3 down vote accepted

will browsers recognize individual files as being the same as pre-cached ones, if they are served from different subdomains?

No. Two identical files served from different locations are different files as far as the browser (cache) is concerned.

The URL is the key by which the file is cached by the browser.

As media1, media2 etc all serve the same files, if over two page requests the same image was served from media1 first, then media2 next, will a browser recognize this or will it download it again?

It will be downloaded again.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.