• 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多实例的环境下,服务器端本地连接到指定实例的问题(sock方式连接)
    binlog2sql实现MySQL误操作的恢复
    MySQL 8.0 新增SQL语法对窗口函数和CTE的支持
    asp.net msbuild 发布
    vue aes
    c# Mono.Cecil IL方式 读MethodBody
    C# IL 生成EXE
    js 动态加载 jq
    mysql 得到指定时间段的日期
    powershell 开windows 端口
  • 原文地址:https://www.cnblogs.com/ranran/p/4565903.html
Copyright © 2020-2023  润新知