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

rexcfnghk
  • 14,435
  • 1
  • 30
  • 57
Ashutosh
  • 201
  • 4
  • 16
  • possible duplicate: [ASP.NET Bundles how to disable minification](http://stackoverflow.com/questions/11944745/asp-net-bundles-how-to-disable-minification) – rexcfnghk Jul 15 '13 at 07: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** – Ashutosh Jul 15 '13 at 09:02
  • please suggest me how can i enable bundling only. – Ashutosh Jul 16 '13 at 06:13

2 Answers2

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();
    }
Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
  • are you running on debug or release mode ? – Cybermaxs Jul 15 '13 at 12:08
  • I used both type one by one but no luck. – Ashutosh Jul 16 '13 at 06:12
  • 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' ;-) – stooboo Aug 09 '14 at 22:20
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
}
Kurkula
  • 6,386
  • 27
  • 127
  • 202