期货大赛项目|十,MVC对js和css的压缩
在Global.asax中添加两行代码
//默认在调试期间,不会启用js和css的压缩
//下面的语句确保了在调试期间也压缩css和js
BundleTable.EnableOptimizations = true;
BundleConfig.RegisterBundles(BundleTable.Bundles);
可以保证在调试中也压缩js和css代码
在BundleConfig中进行js和css的压缩
using System.Web.Optimization; namespace FuturesContest.UI
{
public class BundleConfig
{ // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
#region 后台layout
bundles.Add(new ScriptBundle("~/bundles/layoutJs").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/bootstrap.min.js",
"~/Content/vendors/fastclick/lib/fastclick.js",
"~/Content/vendors/nprogress/nprogress.js",
"~/Content/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js",
"~/Content/vendors/moment/moment.js",
"~/Content/vendors/sweetalert/sweetalert2.min.js",
"~/Scripts/Gentelella/custom.js")); bundles.Add(new StyleBundle("~/Content/layoutCss1").Include(
"~/Content/bootstrap.min.css")); bundles.Add(new StyleBundle("~/Content/Gentelella/layoutCss2").Include(
"~/Content/Gentelella/custom.min.css")); bundles.Add(new StyleBundle("~/Content/vendors/nprogress/layoutCss3").Include(
"~/Content/vendors/nprogress/nprogress.css"
));
bundles.Add(new StyleBundle("~/Content/vendors/sweetalert/layoutCss4").Include(
"~/Content/vendors/sweetalert/sweetalert2.min.css"
)); bundles.Add(new StyleBundle("~/Content/vendors/font-awesome/css/layoutCss5").Include(
"~/Content/vendors/font-awesome/css/font-awesome.min.css"
));
bundles.Add(new StyleBundle("~/Content/vendors/bootstrap-progressbar/css/layoutCss6").Include(
"~/Content/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
)); #endregion #region 前台layout
bundles.Add(new ScriptBundle("~/game/layoutJs").Include(
"~/Scripts/jquery-{version}.js",
"~/Content/vendors/sweetalert/sweetalert2.min.js",
"~/Content/vendors/moment/moment.js",
"~/Scripts/bootstrap.min.js")); bundles.Add(new StyleBundle("~/Content/Game/layoutCss1").Include(
"~/Content/Game/comment.css",
"~/Content/Game/responsive.css",
"~/Content/Game/themes.css")); #endregion #region validate
bundles.Add(new ScriptBundle("~/bundles/validateJs").Include(
"~/Content/vendors/poshytip-1.2/src/jquery.poshytip.min.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/Scripts/common.js",
"~/Scripts/jquery.unobtrusive-ajax.min.js")); //压缩失效
bundles.Add(new StyleBundle("~/Content/vendors/poshytip-1.2/src/tip-yellow/validateCss").Include(
"~/Content/vendors/poshytip-1.2/src/tip-yellow/tip-yellow.css"));
#endregion #region datatables bundles.Add(new ScriptBundle("~/bundles/datatablesJs").Include(
"~/Content/vendors/datatables.net/js/jquery.dataTables.min.js",
"~/Content/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js",
"~/Content/vendors/iCheck/icheck.min.js",
"~/Scripts/datatables.helper.js")); bundles.Add(new StyleBundle("~/Content/vendors/datatables.net-bs/css/datatablesCss1").Include(
"~/Content/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css")); bundles.Add(new StyleBundle("~/Content/vendors/iCheck/skins/flat/datatablesCss2").Include(
"~/Content/vendors/iCheck/skins/flat/green.css")); #endregion #region ueditor bundles.Add(new ScriptBundle("~/bundles/ueditorJs").Include(
"~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/ueditor.config.js",
"~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/ueditor.all.js",
"~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/lang/zh-cn/zh-cn.js",
"~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/ueditor.parse.js")); bundles.Add(new StyleBundle("~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/themes/ueditorCss").Include(
"~/Content/vendors/ueditor1_4_3_3-utf8-net/utf8-net/themes/iframe.css"));
#endregion #region fileinput bundles.Add(new ScriptBundle("~/bundles/fileinputJs").Include(
"~/Content/vendors/bootstrap-fileinput-master/js/fileinput.min.js",
"~/Content/vendors/bootstrap-fileinput-master/js/locales/zh.js",
"~/Scripts/fileHelper.js"
)); bundles.Add(new StyleBundle("~/Content/vendors/bootstrap-fileinput-master/css/fileinputCss").Include(
"~/Content/vendors/bootstrap-fileinput-master/css/fileinput.min.css"));
#endregion #region my97 bundles.Add(new ScriptBundle("~/bundles/my97Js").Include(
"~/Content/vendors/My97DatePicker/WdatePicker.js",
"~/Content/vendors/My97DatePicker/lang/zh-cn.js"
)); bundles.Add(new StyleBundle("~/Content/vendors/My97DatePicker/skin/default/my97Css").Include(
"~/Content/vendors/My97DatePicker/skin/default/datepicker.css"));
#endregion }
}
}
注意:有些JS是无法被压缩的,具体原因不清楚,比如百度的ueditor,my97等
css里面会有图片,压缩之后找不到路径,所以不再一个路径下的css要单独压缩,并保证路径一致
例如
bundles.Add(new StyleBundle("~/Content/vendors/My97DatePicker/skin/default/my97Css").Include(
"~/Content/vendors/My97DatePicker/skin/default/datepicker.css"));
期货大赛项目|十,MVC对js和css的压缩的更多相关文章
- 期货大赛项目|四,MVC的数据验证
上图先看下效果 样式先不说,先了解下数据验证是怎么实现的 一 必须是强类型的视图 二 这些显示提示的话语,都在强类型的实体中 三 必须使用Html.BeginForm或者Html.AjaxBeginF ...
- 【MVC】 js,css 压缩
[MVC] js,css 压缩 一. 引用 System.Web.Optimization.dll : 使用 Nuget ,在控制台输入 Install-Package Microsoft.AspNe ...
- js、css动态压缩页面代码
1.js.css动态压缩页面代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...
- 期货大赛项目|五,表格插件datatatables在MVC中的应用
系统中都需要表格,我见过最好的表格就是Datatables了,但中文文档有限,英文能力有限,就写一些简单用法 上图看效果先 要了分页和排序 基本用法 引入js和css bundles.Add(new ...
- 期货大赛项目|八,ueditor的应用
百度开发的富文本编辑器还是很不错的,可以已经不维护了 下载ueditor1_4_3_3-utf8-net放到项目中 找到net文件夹下config.json 修改以下两行 "imageUrl ...
- 期货大赛项目|六,iCheck漂亮的复选框
废话不多说,直接上图 对,还是上篇文章的图,这次我们不研究datatables,而是看这个复选框,比平常的复选框漂亮太多 看看我是如何实现的吧 插件叫iCheck 用法也简单 引入js和css $(& ...
- 期货大赛项目|九,fileinput插件的应用
引入JS和CSS bundles.Add(new ScriptBundle("~/bundles/fileinputJs").Include( "~/Content/ve ...
- node作为前台的项目如何打包静态js和css并生成版本号,loader插件的使用
一.使用场景: 1.node创建的前台项目需要输入地址展示页面 2.有设置缓存或者cdn的需要在静态文件更改时能使用新的而不是缓存的,需要版本号这里 3.可能需要压缩静态文件的 二.一些参考地址,需要 ...
- 关于ASP.NET MVC的js和css资源管理
本文来源于博客园-钱智慧,转载请注明出处 通过这篇文章和这个回答,我们总结如下: 浏览器针对一个域名,最多只会开启6个线程来加载文件,比如head中如果有7个引入文件(js文件或者css文件)的标签, ...
随机推荐
- [模板] 网络流相关/最大流ISAP/费用流zkw
最大流/ISAP 话说ISAP是真快...(大多数情况)吊打dinic,而且还好写... 大概思路就是: 在dinic的基础上, 动态修改层数, 如果终点层数 \(>\) 点数, break. ...
- DRF之版本控制、认证和权限组件
一.版本控制组件 1.为什么要使用版本控制 首先我们开发项目是有多个版本的当我们项目越来越更新,版本就越来越多,我们不可能新的版本出了,以前旧的版本就不进行维护了像bootstrap有2.3.4版本的 ...
- 通过SQL脚本来查询SQLServer 中主外键关系
在SQLServer中主外键是什么,以及主外键如何创建,在这里就不说了,不懂的可以点击这里,这篇文章也是博客园的博友写的,我觉得总结的很好: 此篇文章主要介绍通过SQL脚本来查看Sqlserver中主 ...
- Android短信备份及插入笔记
实现备份短信到xml文件和像短信中插入一条数据 一.实现短信将备份到xml文件中 在布局文件中定义一个按钮,定义点击事件为copyClick MainActivity.java: package co ...
- HDOJ 5639 Transform
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5637 题意:有一个数x,你可以对x进行两种操作,1.反转x二进制其中任意一位2.x^y(y题目给出), ...
- <数据结构基础学习>(二)简单的时间复杂度分析
一.简单的复杂度分析 O(1) O(n) O(logn) O(logn) O(n^2) 大O描述的是算法的运行事件和输入数据之间的关系 Eg: 数组求和 public static int sum(i ...
- LOJ#2723 多边形
解:首先,n<=20的直接暴力建图然后状压哈密顿回路,相信大家都会.固定1为起点,fi,s表示结尾为i点,状态为s.每次遍历i的出边转移,最后遍历1的出边统计答案.n22n. 然后就是正经题解了 ...
- 读zepto源码之工具函数
读zepto源码之工具函数 Zepto 提供了丰富的工具函数,下面来一一解读. 源码版本 本文阅读的源码为 zepto1.2.0 $.extend $.extend 方法可以用来扩展目标对象的属性.目 ...
- (转)史上最全 40 道 Dubbo 面试题及答案,看完碾压面试官!
背景:因为自己的简历写了dubbo,面试时候经常被问到.实际自己对dubbo的认识只停留在使用阶段,所以有必要好好补充下基础的理论知识. https://zhuanlan.zhihu.com/p/45 ...
- java-查看java源码
安装jdk后,自己的pc下自然而然就可以找到java的源码包.