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. OpenCv全景图像拼接

    http://my.oschina.net/xiaot99/blog/226589 http://blog.csdn.net/chenjiazhou12/article/details/2282548 ...

  2. BestCoder 2nd Anniversary

    A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...

  3. win10休眠选项在哪里设置?如何设置?

    本人以前安装的Win7也是碰到这个问题 http://www.jb51.net/os/win10/373383.html 查询.打开休眠命令 1.右键开始菜单,选择命令提示符(管理员) 或 win+R ...

  4. XML序列化及反序列化

    //对象序列化xml OutModel outmodel = new OutModel(); XmlSerializer serializer = new XmlSerializer(typeof(O ...

  5. sql 动态行转列

    create table u01 (医案编号 varchar(5),药物编号 varchar(5)) insert into u01 select '01','01' union all select ...

  6. python安装第三方类库的方法

    1.先到官网 http://pypi.python.org/pypi/setuptools 下载setuptools.exe文件并安装 点击 ez_setup.py进入, 并将内容复制下来, 保存为本 ...

  7. Some Link: Java Reflection

    http://docs.oracle.com/javase/tutorial/reflect/index.html https://bugs.openjdk.java.net/browse/JDK-4 ...

  8. [Java] 位运算

    https://ckjoker.github.io/2015/03/01/Java-bit-primary/

  9. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  10. Android课程---添加黑名单的练习(课堂讲解)

    DBHelper.java package com.hanqi.test3; import android.content.Context; import android.database.sqlit ...