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. 已解决:Strict Standards: Only variables should be passed by reference in

    今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables should be passed by reference in F:\www.x ...

  2. CookieManager

    CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance() ...

  3. Only Link: Inheritance and the prototype chain

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_cha ...

  4. SOAPUI使用教程-创建MockResponse步骤

    MockResponse测试步骤监听一个SOAP请求并返回一个预先配置的响应,然后再继续. 传入的请求的能被断言检查. 这种TestStep使用场景是例如: 客户端测试,验证传入的请求并返回假或不正确 ...

  5. Android weight属性详解

    android:layout_weight是一个经常会用到的属性,它只在LinearLayout中生效,下面我们就来看一下: 当我们把组件宽度设置都为”match_parent”时: <Butt ...

  6. FK JavaScript之:ArcGIS JavaScript API之地图动画

    地图要素动画应用场景:动态显示地图上的要素的属性随着时间的改变而改变,并根据其属性的变化设置其渲染.比如:某水域项目中,随着时间的变化,动态展现水域的清淤进度 本文目的:对ArcGIS JavaScr ...

  7. mount windows-linux文件共享

    . (2)在linux下访问windows共享: smbclient -L 192.168.2.12 -U admin   //查看共享了那些目录,由此知道主机名为XIAOXING-PC smbcli ...

  8. ouath原理

    1.OAuth的简述 OAuth(Open Authorization,开放授权)是为用户资源的授权定义了一个安全.开放及简单的标准,第三方无需知道用户的账号及密码,就可获取到用户的授权信息,并且这是 ...

  9. Unity学习疑问记录之触摸点坐标

    Vector3 pos=Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); 类似的鼠标点击Camera.main.ScreenToW ...

  10. springmvc HandlerInterceptoer WebRequestInterceptor MethodInterceptor使用

    HandlerInterceptoer拦截的是请求地址,所以针对请求地址做一些验证.预处理等操作比较合适.