0

We recently upgraded our MVC projects to Visual Studio 2013 and ASP.NET 4.5.1 and our bundles containing certain wildcards like:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.min.js"));

have stopped compiling correctly. It seems to be effecting any wildcard containing more characters before '.js', which is usually min.

I realize that part of bundling is minification, so it's not a necessity by some opinions, but is that the intent of this? I've read nothing about this is release notes. It is going to require a lot of effort to go back and fix, as sometimes we don't have the regular versions of these scripts. We are experiencing other wild card issues, but this seems to be the big one. I have yet to see anyone else posting an issue with this, so I'm curious to see if anyone else has noticed it, or if it is a configuration problem we're experiencing due to the upgrade process.

Precious Roy
  • 1,086
  • 1
  • 9
  • 19

1 Answers1

1

You should not add min prefix in your bundle definitions at all.

The bundling framework follows several common conventions such as:

Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist. Selecting the non “.min” version for debug. Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.

Make sure that optimizations are enabled in web.config:

<system.web>
    <compilation debug="false" />
    <!-- Lines removed for clarity. -->
</system.web>

Or override in the code:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
    BundleTable.EnableOptimizations = true;
}

and MVC will generate bundle link with minifed jquery file, something like:

<script src="/bundles/jquery?v=OCFAn1NcaUrZ5VLi0Kt8lefDjHOF7mvtdw-2FUpZjJ01"></script>

UPDATE:

It seems this did not work in earlier versions too. There is workaround by modifying IgnoreList of BundleCollection:

https://stackoverflow.com/a/12005272/186822

Community
  • 1
  • 1
Nenad
  • 24,809
  • 11
  • 75
  • 93
  • I understand how bundles and minification work. I wasn't looking for a reason not to do something, but an explanation as to why something that did work suddenly stopped. And .min issue isn't the only one we're facing. As I see nothing in release notes or articles about these changes. – Precious Roy Oct 28 '13 at 20:31
  • It's not supported feature, it just worked by accident. Nowhere in [documentation](http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification "documentation") of version 4 you'll find example of bundle configuration referencing "min" file. If you reference `file1.min.js`, should bundling engine try to search for `file.min.min.js`? And if `min.min.js` is not there, maybe it should try to minify it? It's ambiguous condition to start with. – Nenad Oct 28 '13 at 20:49