using System.Collections.Concurrent;
using System.Text; namespace System.Web.Optimization
{
public static class Script
{
private static readonly ConcurrentDictionary<string, string> Bundles = new ConcurrentDictionary<string, string>(); public static IHtmlString Src(params string[] paths)
{
string bundlePath = RegisterBundles(paths);
if (string.IsNullOrEmpty(bundlePath))
{
return RenderOrignal(paths);
}
return Scripts.RenderFormat(Scripts.DefaultTagFormat, bundlePath);
} private static IHtmlString RenderOrignal(params string[] paths)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = ; i < paths.Length; i++)
{
string path = paths[i];
if (path.StartsWith("~"))
{
path = path.Substring();
}
stringBuilder.AppendFormat(Scripts.DefaultTagFormat, path);
} return (IHtmlString)new HtmlString(stringBuilder.ToString());
} private static string RegisterBundles(params string[] paths)
{
string key = string.Join(null, paths);
if (Bundles.ContainsKey(key))
{
string bundlePath;
if (Bundles.TryGetValue(key, out bundlePath))
{
return bundlePath;
}
}
else
{
string bundlePath = "~/Scripts/" + Math.Abs(key.GetHashCode());
var bundle = BundleTable.Bundles.GetBundleFor(bundlePath);
if (bundle == null)
{
var scriptBundle = new ScriptBundle(bundlePath);
scriptBundle.Include(paths);
BundleTable.Bundles.Add(scriptBundle);
}
if (Bundles.TryAdd(key, bundlePath))
{
return bundlePath;
}
}
return null;
}
}
}

AutoBundle in asp.net mvc 5的更多相关文章

  1. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库

    在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...

  2. 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus

    最新的Mono 4.4已经支持运行asp.net mvc5项目,有的同学听了这句话就兴高采烈的拿起Visual Studio 2015创建了一个mvc 5的项目,然后部署到Mono上,浏览下发现一堆错 ...

  3. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  4. Asp.net MVC 传递数据 从前台到后台,包括单个对象,多个对象,集合

    今天为大家分享下 Asp.net MVC 将数据从前台传递到后台的几种方式. 环境:VS2013,MVC5.0框架 1.基本数据类型 我们常见有传递 int, string, bool, double ...

  5. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

  6. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之目录导航

    ASP.NET MVC with Entity Framework and CSS是2016年出版的一本比较新的.关于ASP.NET MVC.EF以及CSS技术的图书,我将尝试着翻译本书以供日后查阅. ...

  7. ASP.NET MVC开发:Web项目开发必备知识点

    最近加班加点完成一个Web项目,使用Asp.net MVC开发.很久以前接触的Asp.net开发还是Aspx形式,什么Razor引擎,什么MVC还是这次开发才明白,可以算是新手. 对新手而言,那进行A ...

  8. ASP.NET MVC原理

    仅此一文让你明白ASP.NET MVC原理   ASP.NET MVC由以下两个核心组成部分构成: 一个名为UrlRoutingModule的自定义HttpModule,用来解析Controller与 ...

  9. ASP.NET MVC——模型绑定

    这篇文章我们来讲讲模型绑定(Model Binding),其实在初步了解ASP.NET MVC之后,大家可能都会产生一个疑问,为什么URL片段最后会转换为例如int型或者其他类型的参数呢?这里就不得不 ...

随机推荐

  1. python下编译py成pyc和pyo

     python下编译py成pyc和pyo   其实很简单, 用 python -m py_compile file.py python -m py_compile /root/src/{file1,f ...

  2. tomcat的debug模式启动不了

    这个问题可能是由于eclipse和tomcat的交互而产生的,在以debug模式启动tomcat时,发生了读取文件错误,eclipse自动设置了断点,导致tomcat不能正常启动.解决方法如下,打开b ...

  3. HTML常用属性

    blue:蓝色  red:红色  yellow:黄色  green:绿色  white:白色 gray:灰色 /*去掉下划线*/ text-decoration: none; /*添加下划线*/ te ...

  4. UI控件闪烁及刷新

    我们常常在一个窗口上放置很多控件,在改变窗口大小时,控件会跟着一起闪烁... 此时,可以将窗口添加WS_CLIPCHILDREN属性即可.(如果包含多层,都需要WS_CLIPCHILDREN属性) 默 ...

  5. javascript函数小练习

    求n-m之间数据的和 <script> function num(n,m){ var sum=0; for (var i = n; i <= m; i++) { sum+=i; } ...

  6. 将f2fs文件系统到磁盘

    1·   用git下载f2fs文件系统tools的源代码.下载地址如下:http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.g ...

  7. buyexpressv6

    <script type="text/javascript"> var is_enabled = -1; var checkSubmitFlg = false; var ...

  8. a chip multiprocessor

    COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION A multicore computer ...

  9. SQL TOP 子句、SQL LIKE 操作符、SQL 通配符

    TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是非常有用的. 注释:并非所有的数据库系统都支持 TOP 子句. SQL Server 的语法: S ...

  10. mysql防止数据库重复

    通常我们用来判断数据库重复的使用以下方法: $title ='www.111cn.net'; $sql = "Select * from tablename where title='$ti ...