Search code examples
asp.net-optimization

Conditional minification for specific bundles using System.Web.Optimizations


I am making use of System.Web.Optimizations BundleConfig in my project. I'm running into an issue with a specific jQuery plugin that I'm using on my site. If I add the file to my ScriptBundle it works fine in Debug mode but throws JavaScript errors when I am in Release mode (i.e. set Web.config debug=false). I'm thinking something isn't getting minified correctly.

All others scripts are not giving me any problems so I don't want to affect behavior for all bundles but is there a way to customize for a specific bundle to tell it to use a specific version in debug and the min version in release.

I know the default behavior is for it to look for .min files but I just can't seem to get this to work. Can anyone tell me what I may be missing here? Thanks for your help.

Here is example I split it out by self. This works in debug but not when i set debug=false in web.config

ScriptBundle layoutBundle = new ScriptBundle("~/jsbundles/jquery/layout"); 
layoutBundle.Include("~/Scripts/plugins/jquery.layout-latest.js"); 
bundles.Add(layoutBundle); 

Solution

  • If you just want to turn off minification for one bundle, you can simply switch to a normal Bundle instead of a ScriptBundle and it won't be minified. Then it will serve that bundle in whatever form that you included without running it through minification.