Bundling works, but minimization doesn't work after moving from Asp.Net MVC 3 to MVC 4

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

Question

My work is complete, but minification does NOT work.

Union code

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

and it displays the script tag as follows: (this is true and excellent!)

eg.

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

If you see the code above, it generates a script link, which means the link is working fine, BUT, when I click to see the contents, the JS content will not be reduced, which means the mini-code is NOT working.

Someone please tell me where the problem is or what should be its solution?

Thanks in advance!

+4
source share
1 answer

First make sure you add the scripts as shown 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 package is defined in the 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

"*" is used to combine files in the same directory and has the same prefix or suffix with its name. Suppose you want to add all the script files that exist in the "~ / Script" directory and have "jquery" as the prefix, then you can create a set as shown below:

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

All packages are registered in the Application_Start application of the Global.asax file of your web application.

 protected void Application_Start() { BundleConfig.RegisterBundles(BundleTable.Bundles); // code } 
+2
source

Source: https://habr.com/ru/post/1469177/


All Articles