Project Description

<%: Html.LoadResources()%> - Loads resources(scripts,styles) in a view.
<%: Html.LoadMasterResources("site")%> - Loads resources in a master page "site".

Let's explore above fastest way to load resources in ASP.NET MVC views.

Cdn Management loads different resources (like styles, scripts etc) from configuration file.
It reads resource location (url) from a configuration file and renders it into a page.

During deployment of ASP.NET MVC project, we change location of referenced resources like styles,scripts.
In weird situation, one resource (like jquery.js) may be referenced in multiples pages. At the time of deployment, we need to change those referenced locations with live locations which is time consuming process.

With Cdn Management,resources will be loaded which are configured in a configuration file (like web.config) and deployement time will be minimized.

Examples:
There are 3 ways to use Cdn Management;

Usage 1:
1. Add Reference of CdnManagement into your MVC3 application.
2. Add configuration key for a resource in AppSettings.
e.g.
Let's add below keys;
<add key="Site.css" value="/Content/Site.css" />
<add key="Cdn.Script.jquery" value="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" />
3. Open a view and import the namespce "CdnManagement".
<%@ Import Namespace="CdnManagement" %>
4. Reference resources with Html.Style and Html.Script.
 <%: Html.Style("Site.css")  %>
 <%: Html.Script("Cdn.Script.jquery") %>


Usage 2:
1. Add Reference of CdnManagement into your MVC3 application.
2. Configure resources in AppSettings with below convention;

<add key="{Controller}.{Action}.Site.css" value="/Content/Site.css" />

//For controller "Cdn" and view "View3"
<add key="Cdn.View3.Site.css" value="/Content/Site.css" />
<add key="Cdn.View3.Script.jquery" value="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" />
3. Open a view and import the namespce "CdnManagement".
<%@ Import Namespace="CdnManagement" %>
4. Reference resources with Html.LoadResources().
<%: Html.LoadResources()  %>


Usage 3:
1. Add Reference of CdnManagement into your MVC3 application.
2. Configure resources in AppSettings with below convention;

<add key="master.{Master Page Name}.Site.css" value="/Content/Site.css" />

//For master page "Site.master"
<add key="master.site.Site.css" value="/Content/Site.css" />
<add key="master.site.jquery" value="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" />
3. Open a view and import the namespce "CdnManagement".
<%@ Import Namespace="CdnManagement" %>
4. Reference resources with Html.LoadResources().
<%: Html.LoadMasterResources("site") %> %>


Possible Extensions

1. Use same concept to load other kind of resources like images used in every pages etc

2. There might have lots! :)

Last edited Mar 17, 2011 at 3:59 AM by vrluckyin, version 16