Question

I had successfully been able to bund my JS script and CSS style sheet on one file each using the bundling functionally offered by "system.web.optimization"

public static void RegisterBundler(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/CDN/Content/_LayoutNotAuth").Include("~/CDN/Content/style.css", "~/CDN/Content/select2.css", "~/CDN/Content/StyleUpdates.css", "~/CDN/Content/jquery-ui-1.8.21.custom.css", "~/CDN/Content/jquery.qtip.min.css", "~/CDN/Content/htmlfeedback.css", "~/CDN/Content/facebookInputToken.css", "~/CDN/content/notifications/jquery.gritter.css"));
            bundles.Add(new ScriptBundle("~/CDN/Scripts/_LayoutNotAuth").Include("~/CDN/Scripts/jquery-1.7.1.min.js", "~/CDN/Scripts/modernizr-1.7.min.js", "~/CDN/Scripts/notifications.js", "~/CDN/Scripts/jquery.unobtrusive-ajax.min.js", "~/CDN/Scripts/menu.js", "~/CDN/Scripts/jquery-ui-1.8.23.custom.min.js", "~/CDN/Scripts/Notifications/jquery.gritter.js", "~/CDN/Scripts/jquery.qtip.min.js", "~/CDN/Scripts/json2.min.js", "~/CDN/Scripts/jquery.signalR.min.js", "~/CDN/Scripts/jquery.validate.js", "~/CDN/Scripts/jquery.validate.unobtrusive.min.js", "~/CDN/Scripts/inputs.js", "~/CDN/Scripts/select2.js", "~/CDN/Scripts/jquery.simplemodal.1.4.2.min.js", "~/CDN/Scripts/htmlfeedback/html2canvas.js", "~/CDN/Scripts/htmlfeedback/jquery.htmlfeedback.js", "~/CDN/Scripts/jquery.blockUI.js", "~/CDN/Scripts/jquery.tokeninput.js", "~/CDN/Scripts/RechercheProjet/ProjectSearch.js", "~/CDN/Scripts/jquery.address-1.5.min.js", "~/CDN/Scripts/RechercheProjet/ContractorSearch.js", "~/CDN/Scripts/Contact/ProfileContact.js", "~/CDN/Scripts/RechercheProjet/resultats_recherche.js"));

        }

I’m wondering if I can automatically minify the resulting files using "system.web.optimization" .

Was it helpful?

Solution

To disable bundling and minification use this (this will disable optimization even if debug=true in web.config)

System.Web.Optimization.BundleTable.EnableOptimizations = false;

If you put EnableOptimizations = true this will bundle and minify even if debug=true in web.config

OTHER TIPS

By default all files included in the Bundle would indeed be minified as well, but only in Release mode.

If you want to enable it in Debug mode as well, try adding this to your RegisterBundle method:

BundleTable.EnableOptimizations = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top