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

  • 相关阅读:
    01.Sencha ExtJS 6
    02.Sencha ExtJS 6
    关于Jquery的delegate绑定事件无效
    细说 Form (表单)
    Rquest Request[""];Request.Form[""];Request.QueryString[""]
    一文看懂web服务器、应用服务器、web容器、反向代理服务器区别与联系
    vs 调试不进入断点
    HttpWebRequest类
    C# 利用 Windows服务模板 创建、安装与卸载Windows服务
    如何搭建win10 asp开发环境安装iis10
  • 原文地址:https://www.cnblogs.com/ranran/p/4565903.html
Copyright © 2011-2022 走看看