CSS and "Media" Servers

Hello everyone,

I’m working on a fairly large website. We’ve decided to put all of our media (images, videos, etc) on a second server to reduce the strain on our main server.

That’s all easy and typical.

Now, the question I have is: How do I link to my images in CSS?

From what I can tell, I have three basic options:

  • Use absolute links to the images.
    Downside would be that if we change the location of our media server, I have to manually update every single image. Ugh.
  • Process the CSS as PHP and add the URL in dynamically on the server side.
  • Put the CSS files on the media server as well and keep relative links.

Right now I think I’m going to use the third option. Since all my CSS links are in one place (and dynamic anyways), it’d be the easiest to reconfigure the media server.

Did I miss an option? What do others do?

Thanks.

Why is that such a problem? Just do a search and replace. With any respectable text editor it should take you a few seconds.

Yeah, but it’s broken into several CSS files for various reasons. It also be nice to be able to quickly deploy this to different servers. Using absolute paths adds an extra step to deploying it.

Also, if I were to miss one somehow I wouldn’t necessarily know unless we took a different media server offline and wound up with broken images on a production site.

So, I actually came up with a great solution to this using… (drum roll please)… mod rewrites! =p

Basically, I ended up making it so anything that was /images/… point to a location on our media server. Works great. I just specify that structure everywhere and I can have them on the other server with no problem. Also gives me one central location to change all images in an instant.

Does the mod_rewrite run on the main server (i.e. not the media server) ?
If so, doesn’t that defeat the whole purpose of having a media server in the first place (take strain off of the main server) ?

The rewrite is on the main server. The server already has mod_rewrite for other purposes, so we weren’t adding any extra modules or anything.

The strain is taken off in the sense that it doesn’t have to send all of the large files anymore. Obviously there is a little bit because it has to workout the rewrite, but it doesn’t have to do anything beyond that. It’s not perfect, but it’s better than the alternative of having to change URLs in a dozen places (segmented CSS scripts that are combined together for production).

Couldn’t you put all files on assets.yourwebsite.com and put round robin DNS on that if you ever want to expand to multiple media servers?

Just thinking out loud.

Well, the problem isn’t so much if we move it for the one setup. Generally we have a minimum of two independent environments (production and development), but sometimes we’ll create additional development environments for special purposes, or additional production environments to be stand-alone backups. That’s why I need it configurable at the server level.

We did consider doing some fancy internal DNS stuff as well for our main production environment in our colo, but I needed something more independent as well.

I would probably just take the easy way out and serve the images from wherever you are serving the CSS. Could easily serve the css off the media server if it makes you feel better.

I seriously considered that approach as well, but it’d make our development process a bit clunky.

Unfortunately, I’m not the one that’s going to be maintaining this project the whole time. I’m essentially developing it, then turning it over to someone else for maintenance. I have to make sure the process is as simple as possible for them.

I would like to do it without the rewrites, but with all the optimizations we’re putting in, what the server is actually running, etc., I don’t think it’ll make a noticeable increase in processing.