tags:

views:

80

answers:

3

Currently, for things like background images, our css files have no domain specified. This works both in our development and production environments.

background-image: url(/images/bg.png);

For performance reasons (cookie-less domain), we'd like to switch this:

background-image: url(http://staticimagedomain.com/images/bg.png);

Ideally, we don't hard code those, so our development environments can still pull locally.

Any thoughts on how to best achieve this?

A: 

Entry in the hosts file to redirect staticimagedomain.com to localhost or wherever your test pages serve from?

Not a great solution, but quick and easy.

Ipsquiggle
Good solution, that would work too!
Neil
+2  A: 

I would suggest hosting the CSS files in the cookie-less domain as well, and not just the images. Then you would be able to use relative paths, which will work both in production and in any other environment.

If you deploy your CSS file to the cookie-less domain:

http://staticimagedomain.com/main.css

Then you can leave the relative URLs /images/bg.png, which will work fine from both environments.

CSS files don't need cookies anyway.

Daniel Vassallo
Ah, that makes sense, the images would be relative to the domain of the css file, not the domain of the containing page . . .
Neil
Yes it works fine. Something curious: I was checking for some examples to back up my answer, and I checked the CSS of Stack Overflow, Amazon.com, Yahoo and You Tube, which all use cookie-less domains. All of them host the CSS file on the cookieless domain, but then they still use full absolute URLs to reference the images.
Daniel Vassallo
However I also found this as a further source: http://stackoverflow.com/questions/2488369/serving-css-from-a-static-domain
Daniel Vassallo
A: 

To add to the other sensible answers: Sometimes is useful to have two stylesheets, one for production other for development, with just a few differences (eg: some background-colors) to help identify visually the instances and prevent confusions. Your build-deployment script (Ant) would take care of moving the css files when going to production.

If you are doing this (or think it would be good to do this), then your question has a trivial answer.

leonbloy