ASP.Net MVC 4 Bundles Ignore List

.min JavaScript Files

It all started when I tried to bundle a .min JavaScript file in my ASP.Net MVC 4 application. MVC just completely ignore any .min files I have in BundleConfig.cs.

Obviously, it doesn’t work. OK, it’s not so obvious when it happened to me.

Ignore List

Turn out, ASP.Net MVC 4 Bundles has ignore list. You guess it, the .min extension is included in the ignore list. To override the ignore list:

public static void SetIgnorePatterns(IgnoreList ignoreList)
{
    if (ignoreList == null)
        throw new ArgumentNullException("ignoreList");

    ignoreList.Ignore("*.intellisense.js");
    ignoreList.Ignore("*-vsdoc.js");
    ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
    //ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
    ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
}

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.IgnoreList.Clear();
    SetIgnorePatterns(bundles.IgnoreList);

    // Continue with your code ...
}

That’s it, the .min JavaScript file will now be included in bundling.

Alternatively, you can also rename the JavaScript to remove its .min extension to be included in bundling process. This approach doesn’t require modification of bundle’s Ignore List.

While we are on the subject, it’s important to note that Bundle and Minification are different process. ASP.Net site explains it as:

Bundling

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load  performance.

Minification

Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space and comments and shortening variable names to one character. Consider the following JavaScript function.

Source: MVC 4 Bundling and Minification

1 thought on “ASP.Net MVC 4 Bundles Ignore List”

  1. Thank you so much for this wonderful article and simple solution. This helped me save hours of research. Thank you.

Leave a comment