4

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.

4
  • It could be a syntax error in the Site.css so that the minification fails. Can you run the css through csslint.net or some other validator?
    – Esko
    Commented Jul 13, 2016 at 11:48
  • Please read different between bundle and minfiy. then you find out your answer.
    – Surajghosi
    Commented Jul 13, 2016 at 11:55
  • There was not any major syntax error in my css file @Esko, but that might be problem in other case, so thanks for feedback anyway!
    – Misho
    Commented Jul 13, 2016 at 12:18
  • Thank for advise @Surajghosi
    – Misho
    Commented Jul 13, 2016 at 12:22

1 Answer 1

2

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.

1
  • your answer was brilliant! bundles.IgnoreList.Clear() does magic staff! Just can't thank you enough!
    – Misho
    Commented Jul 13, 2016 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.