3

I am implementing the bundling and minification in MVC4 but its not working when i deploy on IIS server. i used below code in my BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{ 
    bundles.Add(new StyleBundle("~/Content/styles/siteCss").Include("~/Content/styles/reset.css")); 
    bundles.Add(new ScriptBundle("~/siteJsCommon").Include("~/Scripts/html5.js",
        "~/Scripts/jquery.js",
        "~/Scripts/jquery-migrate-1.1.1.js",
        "~/Scripts/jquery-ui-1.10.3.custom.js",
        "~/Scripts/carousel.js",
        "~/Scripts/template.js",
        "~/Scripts/jquery.validate.js",
        "~/Scripts/additional-methods.js",
        "~/Scripts/function.js"));

    BundleTable.EnableOptimizations = true;       
}

Even i checked in my web.config. it seems fine.

<compilation debug="false" targetFramework="4.5" />

can anyone tell me where i am doing mistake. is it possible to enable bundle only?

Thanks ashu

3
  • possible duplicate: ASP.NET Bundles how to disable minification Commented Jul 15, 2013 at 7:19
  • Thanks for your response. To do this, the easiest would be to change the Script/StyleBundles out for plain Bundles which have no Transform set by default, this would turn off minification but still bundle. can you suggest me how to do plain Bundles Commented Jul 15, 2013 at 9:02
  • please suggest me how can i enable bundling only. Commented Jul 16, 2013 at 6:13

2 Answers 2

0

There are built-in no configs/options that allow you to enable bundling without minification.

However, Bundles (Script or Style) use IBundleTransform : Microsoft.Web.Optimisation include two defaults transform type JsMinify and CssMinify which is used by ScriptBundle and StyleBundle respectively. However we can create our own custom transform type to process references as per our need or even better do not use IBundleTransform.

So, to enable bundling without Minification we could try this :

    //somewhere after all bundles are registered 
    foreach (var bundle in bundles)
    {
        bundle.Transforms.Clear();
    }
Sign up to request clarification or add additional context in comments.

3 Comments

are you running on debug or release mode ?
I used both type one by one but no luck.
also for me .... for file 'x.js' in the bundle ensure that there is NOT a 'x.min.js' file in the folder otherwise although you've removed the minification transformation .. bundling will serve out the 'pre' minified file e.g. if you have 'angular.js' then DELETE 'angular.min.js' ;-)
0

You need to register above created bundles with in Application_Start event of Global.asax like as

protected void Application_Start()
{
 RegisterBundles(BundleTable.Bundles);
 // Other Code is removed for clarity
}

Bundling and minification doesn't work in debug mode. So to enable this features you need to add below line of code with in Application_Start event of Global.asax. protected void Application_Start()

{
 BundleConfig.RegisterBundles(BundleTable.Bundles);
 //Enabling Bundling and Minification
 BundleTable.EnableOptimizations = true; 
 // Other Code is removed for clarity
}

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.