views:

324

answers:

4

Hi,

I am building two ASP.NET MVC sites. There is a certain amount of content I wish to be able to share between the two sites. I created a class library and was able to share a large portion of what I needed too. However I would really like to know how I could share contents such as images and javascript files, so I do not have to duplicate them between both web sites.

I would be very grateful if anyone has any good ideas on this.

Thank you

A: 

For javascript you can directly give url as src of JavaScript. e.g.

<script src="some_url_path_/global.js" type="text/javascript"></script>

To share a class I recommend to use web services rather to allow access to class file source.

Vikas
+1  A: 

You could use a CDN (content delivery network) for shared files.

<script src="http://shared.yourdomain/stuff.js" type="text/javascript"></script>

It's the same trick that SO employs, it's good for load time too as the browser will only open 2 connections per domain. Using a CDN means that you can add another 2 connections per CDN used. That can include sub domains on your own site. So you could have js.yourdomain and img.yourdomain and they're all counted as different.

Kieron
+1  A: 

Javascript files and images can be hosted in a common location - for standard javascript files (jquery library etc.) it's a good idea to use a CDN as Kieron points out - you get a lot of benefits there.

For other content files you can just put them on a common url that is accessed by both sites - e.g. with 2 sites on different urls:

http://site1.somedomain.com/default.aspx
http://site2.somedomain.com/default.aspx

they can both use content from a common location like:

http://commoncontent.somedomain.com/images/bigimage1.jpg
http://commoncontent.somedomain.com/scripts/customjavascript1.js

The same thing works with virtual directories instead of a fqdn too of course.

Steve Willcock
A: 

If you have a common assembly you may consider embedding your content as web resources. More info about web resources can be found here.

korchev
Thanks, I tried this and it worked great locally through my development server. When I deployed it seems it can not find the files as they don't get loaded. It is deployed with IIS 6. I pretty much followed this solution http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Extracting-Web-Resources.aspxAny Ideas?
andyJ