Haddar Macdasi
Haddar Macdasi

Reputation: 3555

no request to minify javascripts

MVC4 C# web site, running in debug mode, the code in "BundleConfig" file is has:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
                "~/Scripts/jquery-1.8.2.min.js", 
                "~/Scripts/jquery.simplemodal.js", 
                "~/Scripts/jquery-ui-1.9.2.custom.min.js", 
                "~/Scripts/jquery.validate.js", 
                "~/Scripts/jquery.validate.unobtrusive.min.js", 
                "~/Scripts/site.js", 
                "~/Scripts/jquery.watermark.js", 
                "~/Scripts/jquery.signalR-0.5.3.min.js" ,
                "~/Scripts/jquery.dataTables.js"

In web.config, debug="true"

I open firebug and see that in the "net -> js" tab section, only calls to not minify js is being made. All minify js files are not being requested from the client.

In my layout my code is:

@Scripts.Render("~/bundles/scripts")

The problem started after I installed the "Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.0" package from nuget... when I run the web site in release mode all working good. I don't have the not minify js files and I want to continue working in Debug mode. How can I fix it ? Why no request to minify js from client occurs?

Upvotes: 0

Views: 203

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

When using Bundling and Minification in debug mode, bundling/minification is disabled.

You can override this and force bundling and minification by adding BundleTable.EnableOptimizations = true; to your RegisterBundles.

public static void RegisterBundles(BundleCollection bundles)
{
    //your bundle code
    BundleTable.EnableOptimizations = true;
}

UPDATE: Seeing your comment it seems I misunderstood your question.

When you are in debug mode and BundleTable.EnableOptimizations = false, the .min version of files are NOT used. Instead, the full debug version of the files will be used. So your scripts folder should have BOTH versions of the files: like

jquery-1.9.1.min.js 
jquery-1.9.1.js

In debug mode, jquery-1.9.1.js will be used. In release mode, jquery-1.9.1.min.js will be used.

If you only have one version of the file, then just remove the ".min" from the file name.

Upvotes: 1

Related Questions