代码之家  ›  专栏  ›  技术社区  ›  jstuardo

MVC5捆绑包不适用于某些资源

  •  0
  • jstuardo  · 技术社区  · 7 年前

    这很奇怪。我在BundleConfig.cs中有这些包:

               bundles.Add(new StyleBundle("~/Content/css").Include(
                          "~/Content/bootstrap.css",
                          "~/Content/font-awesome.css",
                          "~/Content/nprogress.css",
                          "~/Content/iCheck/flat/green.css",
                          "~/Content/daterangepicker.css",
                          "~/Content/bootstrap-dialog.css",
                          "~/Content/Tooltipster/css/tooltipster.css",
                          "~/Content/custom.css"));
    
                bundles.Add(new ScriptBundle("~/bundles/gentelella").Include(
                            "~/Scripts/fastclick.js",
                            "~/Scripts/nprogress.js",
                            "~/Scripts/jquery.icheck.js",
                            "~/Scripts/date.js",
                            "~/Scripts/moment-with-locales.js",
                            "~/Scripts/daterangepicker.js",
                            "~/Scripts/validator/validator.js",
                            "~/Scripts/bootstrap-dialog.js",
                            "~/Scripts/jquery.tooltipster.js",
                            "~/Scripts/custom.js"));
    

    奇怪的是,从所有文件中,只有自定义。css和自定义。发布网站时不会呈现js。当我调试时,一切正常。问题只发生在生产现场。

    两者都是自定义的。css和自定义。js未最小化。您可以看到自定义css here here .

    呈现时,所有CSS均加载此URL: http://demo.relojelectronico.cl/Content/css?v=l7FFCONJaEcRHBZMIAQIwzM3XkNczNlgWBYwjHtrumM1

    http://demo.relojelectronico.cl/bundles/gentelella?v=vBQcZjDbD_j0oRIktzJoqND9pbeEqe-jNtQFHZ9YfMM1

    任何帮助都将不胜感激。

    编辑:

    我注意到CSS文件已正确呈现。问题只是custom.js。

    为了测试它,我将其捆绑分开,如下所示:

            bundles.Add(new ScriptBundle("~/bundles/custom").Include(
                    "~/Scripts/custom.js"
                ));
    

    here .

    奇怪的是,最初的JS从以下内容开始:

    /**
     * Resize function without multiple trigger
     * 
     * Usage:
     * $(window).smartresize(function(){  
     *     // code here
     * });
     */
    (function ($, sr) {
        // debouncing function from John Hann
        // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
        var debounce = function (func, threshold, execAsap) {
            var timeout;
    
            return function debounced() {
                var obj = this, args = arguments;
                function delayed() {
                    if (!execAsap)
                        func.apply(obj, args);
                    timeout = null;
                }
    
                if (timeout)
                    clearTimeout(timeout);
                else if (execAsap)
                    func.apply(obj, args);
    
                timeout = setTimeout(delayed, threshold || 100);
            };
        };
    
        // smartresize 
        jQuery.fn[sr] = function (fn) { return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
    
    })(jQuery, 'smartresize');
    /**
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    var CURRENT_URL = window.location.href.split('#')[0].split('?')[0],
        $BODY = $('body'),
        $MENU_TOGGLE = $('#menu_toggle'),
        $SIDEBAR_MENU = $('#sidebar-menu'),
        $SIDEBAR_FOOTER = $('.sidebar-footer'),
        $LEFT_COL = $('.left_col'),
        $RIGHT_COL = $('.right_col'),
        $NAV_MENU = $('.nav_menu'),
        $FOOTER = $('footer');
    
    
    
    // Sidebar
    function init_sidebar() {
        // TODO: This is some kind of easy fix, maybe we can improve this
        var setContentHeight = function () {
            // reset height
            $RIGHT_COL.css('min-height', $(window).height());
    
            var bodyHeight = $BODY.outerHeight(),
                footerHeight = $BODY.hasClass('footer_fixed') ? -10 : $FOOTER.height(),
                leftColHeight = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height(),
                contentHeight = bodyHeight < leftColHeight ? leftColHeight : bodyHeight;
    
            // normalize content
            contentHeight -= $NAV_MENU.height() + footerHeight;
    
            $RIGHT_COL.css('min-height', contentHeight);
            $RIGHT_COL.css('height', contentHeight);
        };
    

    这怎么可能?

    2 回复  |  直到 7 年前
        1
  •  1
  •   jstuardo    7 年前

    我回答我的问题,如果这有助于其他人面对这个问题。

    这没有记录,但我已经发现了问题所在。

    事实证明,在这两个文件夹(内容和脚本)中,都是自定义的缩小版本。css和自定义。js存在(分别名为custom.min.css和custom.min.js)。这些缩小版本不是custom的相应缩小版本。css和自定义。js,但它们是原始的。

    for CSS for JS

    这是结论。在ASP中启用优化时。NET MVC,优化器首先查找等效的“.min.”文件(如果它存在于文件夹中)。如果存在,则会将该文件发送到浏览器。如果没有,则执行缩小。

    这也可能是为什么在捆绑中添加文件的“.min.”版本时,该文件不起作用,并且根本不发送文件的原因。

    干杯

        2
  •  0
  •   Karthik Elumalai    7 年前

    尝试添加

    <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
    

    在web配置中 <modules> under <system.webServer>.

    资料来源: https://forums.asp.net/t/1857743.aspx?Bundling+not+working+when+deployed+to+web+host+works+fine+locally

    Why is my CSS bundling not working with a bin deployed MVC4 app?