Question

As I have migrated from Asp.Net MVC 3 to MVC 4, everything working fine with Asp.Net MVC 4 except minification.

Issue

My bundling works BUT minification is NOT working.

Bundling code

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(
                new Bundle("~/Bundles/Entity").Include(
                "~/Scripts/Module/*.js"));
        }

and it renders the script tag as given below: (which is true and fine!)

e.g.

 <script src="/Bundles/Entity?v=rXIO788liM9pg6AVW5wS7Fxv9LboBMZ5O4ajQRLgk7Y1"></script>

If you see above code, it generates the bundling script reference, which means bundling is working fine, BUT when I click to see the content, the JS content is NOT minified, which means that minification is NOT working.

Would anybody please do let me know that where is the problem OR what should be the resolution of it?

Thanks in advance!

Was it helpful?

Solution

Please first make sure that you have added scripts as like below

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
 "~/Scripts/jquery-1.7.1.min.js",
 "~/Scripts/jquery.validate.min.js",
 "~/Scripts/jquery.validate.unobtrusive.min.js"));

And make sure the above bundle is defined with in BundleConfig class as shown below:

 public class BundleConfig
{
 public static void RegisterBundles(BundleCollection bundles)
 {


bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
 "~/Scripts/jquery-1.7.1.min.js",
 "~/Scripts/jquery.validate.min.js",
 "~/Scripts/jquery.validate.unobtrusive.min.js"));
 }
} 

"*" wildcard character is used to combines the files that are in the same directory and have same prefix or suffix with its name. Suppose you want to add all the scripts files that exist with in "~/Script" directory and have "jquery" as prefix then you can create bundle like below:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery*.js"));

All bundles are registered with in Application_Start event of Global.asax file of you web application.

protected void Application_Start()
{
 BundleConfig.RegisterBundles(BundleTable.Bundles);
 // code
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top