AutoBundle in asp.net mvc 5
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的更多相关文章
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库
在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...
- 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus
最新的Mono 4.4已经支持运行asp.net mvc5项目,有的同学听了这句话就兴高采烈的拿起Visual Studio 2015创建了一个mvc 5的项目,然后部署到Mono上,浏览下发现一堆错 ...
- 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino
大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...
- Asp.net MVC 传递数据 从前台到后台,包括单个对象,多个对象,集合
今天为大家分享下 Asp.net MVC 将数据从前台传递到后台的几种方式. 环境:VS2013,MVC5.0框架 1.基本数据类型 我们常见有传递 int, string, bool, double ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之目录导航
ASP.NET MVC with Entity Framework and CSS是2016年出版的一本比较新的.关于ASP.NET MVC.EF以及CSS技术的图书,我将尝试着翻译本书以供日后查阅. ...
- ASP.NET MVC开发:Web项目开发必备知识点
最近加班加点完成一个Web项目,使用Asp.net MVC开发.很久以前接触的Asp.net开发还是Aspx形式,什么Razor引擎,什么MVC还是这次开发才明白,可以算是新手. 对新手而言,那进行A ...
- ASP.NET MVC原理
仅此一文让你明白ASP.NET MVC原理 ASP.NET MVC由以下两个核心组成部分构成: 一个名为UrlRoutingModule的自定义HttpModule,用来解析Controller与 ...
- ASP.NET MVC——模型绑定
这篇文章我们来讲讲模型绑定(Model Binding),其实在初步了解ASP.NET MVC之后,大家可能都会产生一个疑问,为什么URL片段最后会转换为例如int型或者其他类型的参数呢?这里就不得不 ...
随机推荐
- MIT 6.828 JOS学习笔记6. Appendix 1: 实模式(real mode)与保护模式(protected mode)
在我们阅读boot loader代码时,遇到了两个非常重要的概念,实模式(real mode)和保护模式(protected mode). 首先我们要知道这两种模式都是CPU的工作模式,实模式是早期C ...
- react native TextInput
今天我想说一下react native中的一个控件,TextInput 翻译过来就是文本输入,对应着android中的EditText.我们先看一下官方是怎样描述的.TextInput是一个允许用户在 ...
- Fzu2124 - 吃豆人 BFS
Description 吃豆人是一款非常经典的游戏,游戏中玩家控制吃豆人在地图上吃光所有豆子,并且避免被怪物抓住. 这道题没有怪物,将游戏的画面分成n*m的格子,每格地形可能为空地或者障碍物,吃豆人可 ...
- CS: Marshalling and Unmarshalling, Serialization and Unserialization
Link1: https://en.wikipedia.org/wiki/Marshalling_(computer_science) Quote: " Comparison with se ...
- iOS UIView 动画浅谈
UIView 等会效果简单实现,哪一个登录页面的demo来举例子吧. + (void)animateWithDuration:(NSTimeInterval)duration animations:( ...
- 从网易与淘宝的font-size思考前端设计稿与工作流
本文结合自己对网易与淘宝移动端首页html元素上的font-size这个属性的思考与学习,讨论html5设计稿尺寸以及前端与设计之间协作流程的问题,内容较多,但对你的技术和工作一定有价值,欢迎阅读和点 ...
- [LintCode] Single Number 单独的数字
Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Have you met this question in ...
- Winform TextBox中只能输入数字的几种常用方法(C#)
方法一: private void tBox_KeyPress(object sender, KeyPressEventArgs e) { ; //禁止空格键 )) return; //处理负数 if ...
- Xamarin的不归路-生成安卓错误
编译生成安卓时提示错误 解决方案:删掉此文件夹(C:\Users\***\AppData\Local\Xamarin\)内所以文件夹和文件,再FQ重新编译即可. 2016年9月1日 13:33
- C++实现vector
用了双向链表,快排,<<,=,[]重载,还有erase的实现比较好玩 //my Vecter ;T need "operator<" #include <i ...