0

I am redesigning all of our public-facing websites. These sites will share most assets such as JS, images, CSS, web services, etc., but will be accessed under different domains/subdomains.

I can't be the only person wanting to share all of these resources with common, but separate and unique sites. What is the proper way to go about this?

Steve Costello
  • 380
  • 2
  • 13

2 Answers2

1

The best way is to have a site such as "static.mydomain.com" which hosts your javacript, images, and css. You'll typically have this site set up for some aggressive caching.

For web services, have a site called "services.mydomain.com" which hosts all of your web services.

All of the other sites go to their respective domains.

The main sites will reference all of their artifacts through something like <img src='http://static.mydomain.com/images/myimage.jpg' />

The only real complexity here is with your automated builds. But even that isn't too hard depending on your build server.

Yes, this is a pretty common approach. Further by separating out those static artificats, it makes it easier to shift them to a CDN at a later date if you want.

NotMe
  • 87,343
  • 27
  • 171
  • 245
  • I like this. How about this: how does one point to different URLs (static.mydomain.com, .dev, .qa) depending on environment without doing a bunch of codebehind work or complicating the actual coding of markup? – Steve Costello May 02 '11 at 21:13
  • 1
    @Steve Costello: config files.. You can use config transformations so that you automatically swap out the settings based on the build you are doing – NotMe May 02 '11 at 21:15
  • Oh, I get that. But I mean specifically if I am refering to, say, an image in the mark. My HTML in DEV should point to static.domain.DEV/images (since the image will not yet be in production), but in production, that same src would point to static.domain.COM/images - since this code is in the markup, and not server-dependent code, what is the best way to go about automagically making those URLs point to the correct place? – Steve Costello May 02 '11 at 21:22
  • @Steve: I can think of a couple ways to do this. The first is a simple modification to your local host file that retargets the regular "static.domain.com" to a test server. The second involves a HttpModule which would intercept urls pointing to "static.domain.com" and change them out to "static.domain.DEV" if it's turned on. Similar to URL rewriting. – NotMe May 02 '11 at 21:55
  • 1
    @Steve: Look at the following for a simple way to rerwite the entire url. http://weblogs.asp.net/owscott/archive/2010/01/26/iis-url-rewrite-hosting-multiple-domains-under-one-site.aspx – NotMe May 02 '11 at 22:00
  • I was thinking about just that last night over a 12-year single malt :) That URL Rewriting on the server was probably the answer. Thanks for the link... I'll look into it. On a side note: is this really such a unique case? And if not, why do we have to jump through so many hoops to make this happen? Or do people just not try to reuse as much code and other assets as they could? – Steve Costello May 03 '11 at 15:56
  • @Steve Costello: A lot of sites don't do this because they either don't have the traffic levels necessary, or don't have multiple sites.. So tool support is pretty low. – NotMe May 03 '11 at 18:42
1

If you want all the files to be part of the same solution then it is very similar to the problem of Sharinging Master Pages across Projects

Checkout the links on that question and the following links:

If you're only concerned about sharing static files, not dynamic, then I'd suggest following Chris Lively's advise and host them on a separate domain. Customize your build process to copy the files when necessary.

Community
  • 1
  • 1
jColeson
  • 951
  • 1
  • 14
  • 24