Reputation: 1080
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.
Upvotes: 3
Views: 2058
Reputation: 30671
If you have a common assembly you may consider embedding your content as web resources. More info about web resources can be found here.
Upvotes: 2
Reputation: 27107
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.
Upvotes: 2
Reputation: 26849
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.
Upvotes: 1
Reputation: 24322
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.
Upvotes: 1