zoukankan      html  css  js  c++  java
  • ASP.NET MVC 4 的JS/CSS打包压缩功能-------过滤文件

    今天在使用MVC4打包压缩功能@Scripts.Render("~/bundles/jquery") 的时候产生了一些疑惑,问什么在App_Start文件夹下BundleConfig.cs文件内

     

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

    这样写可以,但是

     

     

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


    这样写却不可以,我的目录里明明有

    [csharp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
     
    1. "~/Scripts/jquery.unobtrusive-ajax.min.js"  

    这个文件啊

     

    通过调试跟踪发现,MVC内部已经对“.min.js”文件做了过滤


    通过反编译这个DLL文件


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

     

     

     

    [csharp] view plaincopyprint?在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文件不起作用的原因了。

  • 相关阅读:
    修改MySQL数据文件的位置
    服务名无效。请键入 NET HELPMSG 2185 以获得更多的帮助。
    索引的讲解
    运行php程序时,浏览器跳出打开和保存提示框
    ora-4031错误
    MySQL_Oracle_事物的隔离级别
    GNU与Linux
    计算机网络_第一章
    Linux网卡高级命令
    Linux RAID简介
  • 原文地址:https://www.cnblogs.com/ranran/p/4565903.html
Copyright © 2011-2022 走看看