栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

浅谈ASP.NET中MVC 4 的JS/CSS打包压缩功能

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

浅谈ASP.NET中MVC 4 的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文件

可以看到下面反编译后的代码:

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文件不起作用的原因了。

以上所述就是本文的全部内容了,希望大家能够喜欢。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/56821.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号