主页 > 知识库 > 浅谈ASP.NET中MVC 4 的JS/CSS打包压缩功能

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

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

您可能感兴趣的文章:
  • 使用asp.net MVC4中的Bundle遇到的问题及解决办法分享
  • 基于Asp.Net MVC4 Bundle捆绑压缩技术的介绍
  • asp.net Bundle功能扩展
  • ASP.NET MVC Bundles 用法和说明(打包javascript和css)
  • ASP.NET MVC中使用Bundle打包压缩js和css的方法
  • Asp.net程序优化js、css实现合并与压缩的方法
  • Asp.net MVC下使用Bundle合并、压缩js与css文件详解

标签:随州 梧州 西双版纳 开封 威海 乌兰察布 广西 甘孜

巨人网络通讯声明:本文标题《浅谈ASP.NET中MVC 4 的JS/CSS打包压缩功能》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266