发布于 2016-06-23 08:24:32 | 152 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


打包(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文件

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


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

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



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务