ASP.NET MVC 4 的JS/CSS打包壓縮功能-------過濾文件

今天在使用MVC4打包壓縮功能@Scripts.Render("~/bundles/jquery") 的時候產生了一些疑惑,問什麼在App_Start文件夾下BundleConfig.cs文件內css

 

[csharp]  view plain copy print ? 在CODE上查看代碼片 派生到個人代碼片
 
  1. bundles.Add(new ScriptBundle("~/bundles/jquery").Include(  
  2.                         "~/Scripts/jquery-{version}.js",  
  3.                         "~/Scripts/jquery.unobtrusive-ajax.js"  
  4.                         ));  

這樣寫能夠,可是jquery

 

 

[csharp]  view plain copy print ? 在CODE上查看代碼片 派生到個人代碼片
 
  1. bundles.Add(new ScriptBundle("~/bundles/jquery").Include(  
  2.                         "~/Scripts/jquery-{version}.js",  
  3.                         "~/Scripts/jquery.unobtrusive-ajax.min.js"  
  4.                         ));  


這樣寫卻不能夠,個人目錄裏明明有
ajax

[csharp]  view plain copy print ? 在CODE上查看代碼片 派生到個人代碼片
 
  1. "~/Scripts/jquery.unobtrusive-ajax.min.js"  

這個文件啊

spa

 

經過調試跟蹤發現,MVC內部已經對「.min.js」文件作了過濾.net


經過反編譯這個DLL文件debug


能夠看到下面反編譯後的代碼:調試

 

 

 

[csharp]  view plain copy print ? 在CODE上查看代碼片 派生到個人代碼片
 
  1. public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)  
  2. {  
  3.     if (ignoreList == null)  
  4.     {  
  5.         throw new ArgumentNullException("ignoreList");  
  6.     }  
  7.     ignoreList.Ignore("*.intellisense.js");  
  8.     ignoreList.Ignore("*-vsdoc.js");  
  9.     ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);  
  10.     ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);  
  11.     ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);  
  12. }  

 

由此咱們能夠知道MVC默認幫咱們過濾了後綴名爲 .intellisense.js、-vsdoc.js、.debug.js、.min.js、.min.css的文件,這也就是咱們引用.min.js文件不起做用的緣由了。code

相關文章
相關標籤/搜索