views:

200

answers:

1

So here's the deal,

I am building out a site right now and want to plan for the future, in terms of performance and such. One performance trick that I've been reading about lately talks about placing images, javascript, and css (all static) files on a separate subdomain/s so that the client will experience a faster download experience when they hit the site.

I understand why this works and am not looking for an explanation of that, but how do I go about setting up my site (makes use PHP) to automatically reference these sub domains when the site leaves my local dev environment?

Right now images can be found here in the local/dev site:

http://localhost/mysitename/assets/css/images/img1.gif

Production site:

http://www.mysitename.com/assets/css/images/img1.gif

I would like to have my Production (Just production, not the local/dev environment) server point to the following:

http://images.mysitename.com/img1.gif

I am wondering how to do this is some automated way? Without having to manually make this change across all of the static files found on the site. (Maybe htaccess but not sure how)

Thank you.

+2  A: 

Define a constant that you use:

define('IMAGE_PATH', 'http://www.mysitename.com/assets/css/images/');

Then use it when printing out the paths:

<img src="<?php echo IMAGE_PATH; ?>img1.gif" />

You just need to mind your paths. When you're ready to swap over, just change the definition of the IMAGE_PATH constant.

Nathan Loding
Thanks Nathan, but this doesn't help me within CSS files? If I'm not mistaken, you can't make use of PHP within a css file. So then what about all the images being called by css. My bad, as I didn't mention that this was the aim in the first place.
dnyce
Whoops!Again, my bad. I figured out what I was doing wrong when I really sat down and thought about it. Nathan your answer is right on target!Thanks again.I'll remember to keep away from the energy drinks when coding from now on. :-)
dnyce