1

I'm using ASP.Net MVC.

For some reason my JS files are NOT minifying. My CSS is minifying fine.

My CSS minifies to: <link href="/ffee/content/css?v=vaNo49ei5GzRQAYnj-AD-AbQI3GKNs2OZ8q6-oJEEvk1" rel="stylesheet"> but all of my JS files are listed separately in the source.

I am compiling and publishing in Release mode.

Can anyone please advise on how I can resolve this please?

Thank you,

Mark

BootstrapBundleConfig.cs

using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;

namespace BootstrapSupport
{
public class BootstrapBundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/js").Include(
            "~/Scripts/jquery-{version}.js",
            "~/Scripts/jquery-migrate-{version}.js",
            "~/Scripts/bootstrap.js",
            "~/Scripts/jquery.validate.js",
            "~/scripts/jquery.validate.unobtrusive.js",
            "~/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js",
            "~/Scripts/knockout-2.2.0.js",
            "~/Scripts/bootstrap-combobox.js",
             "~/Scripts/select2.js"
            ));

        bundles.Add(new ScriptBundle("~/mt").Include(
           "~/Scripts/bootstrap-datepicker.js",
                            "~/Scripts/mtDateEdit.js",
                            "~/Scripts/jquery-te-1.4.0.js"
                            //"~/Scripts/tinymce/tinymce.js"
                            ));

        bundles.Add(new StyleBundle("~/content/css").Include(
            "~/Content/bootstrap.css",
            "~/Content/body.css",
            "~/Content/bootstrap-responsive.css",
            "~/Content/bootstrap-mvc-validation.css",
            "~/Content/bootstrap-combobox.css",
             "~/Content/select2.css",
            "~/Content/datepicker.css",
            "~/Content/jquery-te-1.4.0.css"
            ));
    }
}
}

Global.asax.cs

   public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();

        BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);

        BootstrapMvcSample.ExampleLayoutsRouteConfig.RegisterRoutes(RouteTable.Routes);
        RegisterViewMapper();
    }

_Bootstrap.Layout.Basic.cshtml - at the bottom of the file:

 <div class="container">
     @Scripts.Render("~/js")
     @Scripts.Render("~/mt")
     @RenderSection("Scripts", required: false)

     @Html.Partial("_alerts")
     @Html.Partial("_validationSummary")
     @RenderBody()   

 </div>
4
  • Are you in debug or release mode? Commented Jan 23, 2014 at 12:33
  • Hi - Release mode. My CSS minifies to: <link href="/ffee/content/css?v=vaNo49ei5GzRQAYnj-AD-AbQI3GKNs2OZ8q6-oJEEvk1" rel="stylesheet"/> - but all of my JS files are listed separately in the source. Thanks, Mark Commented Jan 23, 2014 at 12:34
  • Did you try forcing it with BundleTable.EnableOptimizations = true; Commented Jan 23, 2014 at 12:38
  • Hi @lalibi - thank you that worked. Looks like there are minification errors, and thats perhaps why it didn't work automatically. Please post an answer, and I'll mark is as such. Thank you, Mark Commented Jan 23, 2014 at 13:03

2 Answers 2

2

Try forcing it with BundleTable.EnableOptimizations = true;

If there are minification/bundling errors, as you state, remove one by one the *.js files from the bundle, until you find the offending one. Once you do find it, try adding a linefeed to the top and the end of this file.

Sign up to request clarification or add additional context in comments.

Comments

2

You can force it for only release mode just add below code in Application_Start

 #if RELEASE            
        BundleTable.EnableOptimizations = true;            
 #endif

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.