Reputation: 7042
I'm thinking about adding another static server to a web app, so I'd have static1.domain.tld and static2.domain.tld.
The point would be to use different domains in order to load static content faster ( more parallel connections at the same time ), but what 'troubles' me is "how to get user's browser to see static1.domain.tld/images/whatever.jpg
and static2.domain.tld/images/whatever.jpg
as the same file" ?
Is there a trick to accomplish this with headers or I'll have to define which file is on which server?
Upvotes: 1
Views: 216
Reputation: 42200
This serverfault question will give you a lot of information: Best way to load balance across multiple static file servers for even an bandwidth distribution?
Upvotes: 1
Reputation: 137577
You need to have both servers able to respond to requests sent to static.domain.tld
. I've seen a number of ways of achieving this, but they're all rather low level. The two I'm aware of:
You can also do the spreading out at the "visible" level by directing to different servers based on something that might as well be random (e.g., a particular bit from the MD5 hash of the path). And, best of all, all of these techniques use independent parts of the software stack to work; you can use them in any combination you want.
Upvotes: 1
Reputation: 15762
No, there's no way to tell the browser that two URLs are the same -- the browser caches by full URL.
What you can do is make sure you always use the same url for the same image. Ie. all images that start with A-M go on server 1, N-Z go on server 2. For a real implementation, I'd use a hash based on the name or something like that, but there's probably libraries that do that kind of thing for you.
Upvotes: 3