期货大赛项目|十,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文件)的标签, ...
随机推荐
- python之路4-文件操作
对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 f = open('lyrics','r',encoding='utf-8') read_line = f.r ...
- Python——装饰器
1.装饰器形成的过程 2.装饰器的作用 3.原则:开放封闭原则 开放:对扩展是开放的 封闭:对修改是封闭的 4.装饰器的固定模式 def func(): time.sleep(0.01) ') def ...
- 【设计模式】【应用】使用模板方法设计模式、策略模式 处理DAO中的增删改查
原文:使用模板方法设计模式.策略模式 处理DAO中的增删改查 关于模板模式和策略模式参考前面的文章. 分析 在dao中,我们经常要做增删改查操作,如果每个对每个业务对象的操作都写一遍,代码量非常庞大. ...
- 【洛谷P3605】晋升者计数
题目大意:给定一棵 N 个点的树,点有点权,求对于每个点来说,以该点为根的子树内比该点点权小的点的个数. 题解:考虑对于每个点开一棵权值线段树.递归过程中,将子树的信息合并到父节点上,统计答案后,再将 ...
- <六>企业级开源仓库nexus3实战应用–使用nexus3配置yum私有仓库
一两个星期之前,你如果在我跟前说起私服的事情,我大概会绕着你走,因为我对这个东西真的一窍不通.事实上也正如此,开发同学曾不止一次的跟我说公司的私服版本太旧了,许多新的依赖编译之后不会从远程仓库自动缓存 ...
- Redis扩展机制
Redis扩展机制扫盲 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 关于Redis的Avalibility解决方案有很多,比如Twemproxy,Codis, 一.Twempro ...
- velocity 新手用小常识--开源,简单易上手
项目中经常用到的 .vm 后缀文件是什么? 基于 java 的 velocity 模版引擎的一种页面控制文件,是一些类似 html 语句和一种叫 VLT 的语句构成 velocity --美 [v ...
- 前端面试题整理—Vue篇
1.对vue的理解,有什么特点,vue为什么不能兼容IE8及以下浏览器 vue是一套用于构建用户界面的渐进式框架,核心是一个响应的数据绑定系统 vue是一款MVVM框架,基于双向绑定数据,当数据发生 ...
- 基于Windows,Python,Theano的深度学习框架Keras的配置
1.安装Anaconda 面向科学计算的Python IDE--Anaconda 2.打开Anaconda Prompt 3.安装gcc环境 (1)conda update conda (2)cond ...
- 代码,java_web
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...