Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BundleTable.EnableOptimizations doesn't work asp mvc

I have very strange problem in MVC BundleConfig file. Before publishing my site I set BundleTable.EnableOptimizations to true, and was waiting that my css file would be minimized after publishing. But one file from ScriptBundle is minified, and another one from same ScriptBundle isn't. Here is what I mean:

my BundleConfig code:

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/Site.css"));

        BundleTable.EnableOptimizations = true;

and in _Layout I have:

@Styles.Render("~/Content/css")

So result of this code is that, when I check sources of site in browser, there is one css file, where my bootstrap.css and Site.css files are combined, but bootstrap.css is minified, and Site.css isn't. I just can't figure out why system doesn't minifies my Site.css file.

It's the weirdest problem I had ever had, so if you know what's going on, please help me.

like image 322
Misho Avatar asked Oct 20 '25 23:10

Misho


1 Answers

you should try the following code

public static void RegisterBundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/Site.css"));

BundleTable.EnableOptimizations = true;
}

using IgnoreList you can bypass any already minified css that is not including in bundle ,because its already minified and mvc bundle will ignore it. If this doesnt work you need to validate your css, you can use web essentials to validate your css. Hope this helps.

like image 173
Alok Avatar answered Oct 23 '25 13:10

Alok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!