Asp.net mvc捆绑。合并效果很好。但压缩和缩小不起作用

时间:2013-08-26 23:20:56

标签: asp.net asp.net-mvc asp.net-mvc-4 bundle

我的所有javascript和css结合在一起。但是,当我看到他们没有缩小。我不知道为什么。

我的包裹如下所示:

         bundles.Add(new Bundle("~/bundles/jqueryval").Include(
            "~/Scripts/jquery-ui.js",
            "~/Scripts/jquery.validate.js",
            "~/Scripts/grid.locale-tr.js",
            "~/Scripts/jquery.jqGrid.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/messages_tr.js",
             "~/Scripts/jquery.form.js"
           )
       );
        bundles.Add(new Bundle("~/bundles/mainjs").Include(
            "~/Scripts/jquery-1.10.2.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/superfish.js",
            "~/Scripts/jquery.flexslider.js",
            "~/Scripts/jquery.kwicks-1.5.1.js",
            "~/Scripts/jquery.easing.1.3.js",
            "~/Scripts/jquery.cookie.js",
            "~/Scripts/touchTouch.jquery.js"
           )
       );

        bundles.Add(new Bundle("~/bundles/allcss").Include(
           "~/Content/Css/bootstrap*",
           "~/Content/Css/opa-icons.css",
           "~/Content/Css/charisma-app.css",
           "~/Content/Css/ui.jqgrid.css",
           "~/Content/Css/jquery-ui.css"
           )
       );

        bundles.Add(new Bundle("~/bundles/maincss").Include(
           "~/Content/Css/bootstrap.css",
           "~/Content/Css/responsive.css",
           "~/Content/Css/style.css",
           "~/Content/Css/touchTouch.css",
           "~/Content/Css/kwicks-slider.css"
           )
       );

我的全球性asax如下所示:

        protected void Application_Start()
    {
#if DEBUG
        BundleTable.EnableOptimizations = false;
#else
                    BundleTable.EnableOptimizations = true;
#endif
        AreaRegistration.RegisterAllAreas();
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        GlobalConfiguration.Configuration.MessageHandlers.Add(new CorsHandler());
    }

 @System.Web.Optimization.Scripts.Render("~/bundles/mainjs")
 @System.Web.Optimization.Styles.Render("~/bundles/maincss")

2 个答案:

答案 0 :(得分:19)

他们没有缩小,因为你使用的是Bundle而不是ScriptBundle。一个 Bundle 只捆绑它们(嘿,一句话:) :)一个 ScriptBundle 捆绑并缩小。

答案 1 :(得分:7)

它们不会缩小,因为您可能处于DEBUG模式。

尝试设置此

BundleTable.EnableOptimizations = true;

看看会发生什么。