3

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.

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

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 blog.eworldui.net/post/2008/05/… Any Ideas?
1

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.