最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net Bundle功能擴(kuò)展

 更新時(shí)間:2012年11月26日 14:52:32   作者:  
發(fā)現(xiàn)這個(gè)東西確實(shí)非常實(shí)用,且功能強(qiáng)大,BundleTable.Bundles能夠壓縮合并js和CSS,但是目前的使用起來(lái)不是特別好需要修改BundleConfig的代碼
前言
新建Asp.net MVC4項(xiàng)目的時(shí)候,在Global.asax.cs里面發(fā)現(xiàn)多了一句代碼
BundleConfig.RegisterBundles(BundleTable.Bundles)
google了以后終于弄清楚了這個(gè)的作用,發(fā)現(xiàn)這個(gè)東西確實(shí)非常實(shí)用,且功能強(qiáng)大,能夠壓縮合并js和CSS,但是目前的使用起來(lái)不是特別好,如果添加js或者css文件的話,需要修改BundleConfig的代碼。
這里我自己簡(jiǎn)單修改了BundleConfig,對(duì)這個(gè)進(jìn)行簡(jiǎn)單的擴(kuò)展。
下面貼出代碼
先貼配置文件BundleConfig.xml(文件放在網(wǎng)站目錄下路徑見(jiàn)代碼中變量BundleConfigPath)
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<Scripts>
<Script Path="~/bundles/jquery">
<File>~/Scripts/jquery-{version}.js</File>
</Script>
<Script Path="~/bundles/jqueryui">
<File>~/Scripts/jquery-ui-{version}.js</File>
</Script>
<Script Path="~/bundles/jqueryval">
<File>~/Scripts/jquery.unobtrusive*</File>
<File>~/Scripts/jquery.validate*</File>
</Script>
<Script Path="~/bundles/modernizr">
<File>~/Scripts/modernizr-*</File>
</Script>
<Script Path="~/bb/aa">
<File>~/Views/Home/addda.js</File>
</Script>
</Scripts>
<Styles>
<Style Path="~/Content/themes/base/css">
<File>~/Content/themes/base/jquery.ui.core.css</File>
<File>~/Content/themes/base/jquery.ui.resizable.css</File>
<File>~/Content/themes/base/jquery.ui.selectable.css</File>
<File>~/Content/themes/base/jquery.ui.accordion.css</File>
<File>~/Content/themes/base/jquery.ui.autocomplete.css</File>
<File>~/Content/themes/base/jquery.ui.button.css</File>
<File>~/Content/themes/base/jquery.ui.dialog.css</File>
<File>~/Content/themes/base/jquery.ui.slider.css</File>
<File>~/Content/themes/base/jquery.ui.tabs.css</File>
<File>~/Content/themes/base/jquery.ui.datepicker.css</File>
<File>~/Content/themes/base/jquery.ui.progressbar.css</File>
<File>~/Content/themes/base/jquery.ui.theme.css</File>
</Style>
<Style Path="~/Content/css">
<File>~/Content/site.css</File>
</Style>
</Styles>
</root>

代碼文件:BundleConfig.cs
復(fù)制代碼 代碼如下:

public class BundleConfig
{
public static string BundleConfigPath = "~/Config/BundleConfig.xml";
/// <summary>
/// Register Bundles From XML
/// </summary>
/// <param name="bundles"></param>
public static void RegisterBundles(BundleCollection bundles)
{
XmlDocument doc = new XmlDocument();
doc.Load(HttpContext.Current.Server.MapPath(BundleConfigPath));
XmlNode root = doc.DocumentElement;
// Regester Script
XmlNodeList ScriptList = root.SelectNodes("Scripts/Script");
if (ScriptList != null && ScriptList.Count > 0)
{
foreach (XmlNode node in ScriptList)
{
string path = CheckNodeRegedit(node);
if (string.IsNullOrEmpty(path)) continue;
var bound = new ScriptBundle(path);
List<string> files = GetFilesFormNode(node);
if (files.Count > 0)
{
bound.Include(files.ToArray());
bundles.Add(bound);
}
}
}
// Regester Style
XmlNodeList StyleList = root.SelectNodes("Styles/Style");
if (StyleList != null && StyleList.Count > 0)
{
foreach (XmlNode node in StyleList)
{
string path = CheckNodeRegedit(node);
if (string.IsNullOrEmpty(path)) continue;
var bound = new StyleBundle(path);
List<string> files = GetFilesFormNode(node);
if (files.Count > 0)
{
bound.Include(files.ToArray());
bundles.Add(bound);
}
}
}
doc = null;
}
/// <summary>
/// 如果內(nèi)容為空則不添加
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private static List<string> GetFilesFormNode(XmlNode node)
{
List<string> files = new List<string>();
foreach (XmlNode nodeFile in node.ChildNodes)
{
if (!string.IsNullOrEmpty(nodeFile.InnerText.Trim()))
files.Add(nodeFile.InnerText.Trim());
}
return files;
}
/// <summary>
/// 檢查注冊(cè)的Node
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private static string CheckNodeRegedit(XmlNode node)
{
XmlAttribute pathAtt = node.Attributes["Path"];
string path = string.Empty;
if (pathAtt == null || string.IsNullOrEmpty(pathAtt.Value.Trim()) || node.ChildNodes.Count == 0)
return string.Empty;
else
return pathAtt.Value.Trim();
}
}

相關(guān)文章

最新評(píng)論

唐海县| 杭州市| 平定县| 芦溪县| 达州市| 莱芜市| 祁门县| 满城县| 武功县| 合川市| 密山市| 洛宁县| 台南县| 崇左市| 开远市| 开原市| 中方县| 榆中县| 德清县| 谷城县| 德江县| 桐城市| 夏津县| 韶关市| 武城县| 五常市| 林甸县| 吴堡县| 华坪县| 镇赉县| 庆阳市| 雅江县| 霍林郭勒市| 酉阳| 祁阳县| 怀远县| 靖远县| 青神县| 抚顺市| 潮安县| 清苑县|