浅谈ASP.NET中MVC 4 的JS/CSS打包压缩功能
网络编程 2021-07-04 22:41www.168986.cn编程入门
打包(Bundling)及压缩(Minification)指的是将多个js文件或css文件打包成单一文件并压缩的做法,如此可减少浏览器需下载多个文件案才能完成网页显示的延迟感等,能有效缩小文件案体积,提高传输效率,提供使用者更流畅的浏览体验。
今天在使用MVC4打包压缩功能@Scripts.Render("~/bundles/jquery") 的时候产生了一些疑惑,问什么在App_Start文件夹下BundleConfig.cs文件内
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery.unobtrusive-ajax.js" ));
这样写可以,但是
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/jquery.unobtrusive-ajax.min.js" ));
这样写却不可以,我的目录里明明有
"~/Scripts/jquery.unobtrusive-ajax.min.js"
这个文件啊
通过调试跟踪发现,MVC内部已经对“.min.js”文件做了过滤
通过反编译这个DLL文件
可以看到狼蚁网站SEO优化反编译后的代码:
public static void AddDefaultIgnorePatterns(IgnoreList ignoreList) { if (ignoreList == null) { throw new ArgumentNullException("ignoreList"); } ignoreList.Ignore("*.intellisense.js"); ignoreList.Ignore("*-vsdoc.js"); ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled); ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled); ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled); }
由此我们可以知道MVC默认帮我们过滤了后缀名为 .intellisense.js、-vsdoc.js、.debug.js、.min.js、.min.css的文件,这也就是我们引用.min.js文件不起作用的原因了。
以上所述就是本文的全部内容了,希望大家能够喜欢。
上一篇:ASP.NET创建动态缩略图的方法
下一篇:.NET逻辑分层架构总结
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程