I ended up going a different direction with this and decided to store all the script and css references, for both CDNs and local files, in the appsettings of the web.config and then have a single htlmhelper method to render to the page.
Web.Config
<appSettings>
<add key="refJSJquery" value="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
<add key="refJSJqueryUI" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" />
<add key="refJSJqueryValidate" value="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js" />
<add key="refJSMicrosoftAjax" value="http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js" />
<add key="refCSSJqueryUI" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" />
<add key="refCSSSite" value="/Public/Css/Site.css"/>
<add key="refCSSIe" value="/Public/Css/ie.css"/>
<add key="refCSSPrint" value="/Public/Css/print.css"/>
<add key="refCSSScreen" value="/Public/Css/screen.css"/>
<add key="refCSSScreen" value="/Public/Css/plugins/buttons/screen.css"/>
<add key="refCSSScreen" value="/Public/Css/plugins/fancy-type/screen.css"/>
</appSettings>
HtmlHelper.cs Method
public static String GetReferences(this HtmlHelper helper)
{
StringBuilder refs = new StringBuilder();
foreach (String name in ConfigurationManager.AppSettings.AllKeys)
{
if (name.StartsWith("ref"))
{
if (name.StartsWith("refCSS"))
refs.Append(string.Format("<link rel='stylesheet' type='text/css' href='{0}'/>
", ConfigurationManager.AppSettings[name]));
else if (name.StartsWith("refJS"))
refs.Append(string.Format("<script src='{0}'></script>
", ConfigurationManager.AppSettings[name]));
}
}
return refs.ToString();
}
Render on Masterpage
<head runat="server">
<title></title>
<%=Html.GetReferences()%>
</head>
Output
<head><title></title><script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script>
<script src='http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js'></script>
<script src='http://ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js'></script>
<link rel='stylesheet' type='text/css' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css'/>
<link rel='stylesheet' type='text/css' href='/Public/Css/Site.css'/>
<link rel='stylesheet' type='text/css' href='/Public/Css/ie.css'/>
<link rel='stylesheet' type='text/css' href='/Public/Css/print.css'/>
<link rel='stylesheet' type='text/css' href='/Public/Css/plugins/fancy-type/screen.css'/>
</head>
Patrick McNamara, BS-IS/CS, MBA, MAED
ASP.NET Web Application Developer
Asteryx, LLC.
http://asteryx.com
pat@asteryx.com