Catégorie : Programmation

How to Minify and Bundle files in ASP.NET MVC

How to Minify and Bundle files in ASP.NET MVC

In ASP.NET MVC – Now ASP.NET CORE – you can create bundles, at runtime, all your files in a bundle are merged into one. You can create Bundles for Script and Style files.

To activate activate Minification and Bundling you can simply set the EnableOptimizations Attribute of the Static class BundleTable to True in the RegisterBundles method. You will find her in the BundleConfig.cs in the App_Start folder of your project.

using System.Web.Optimization;

namespace Hosteam.Web.MVCBootstrap
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            //Enable Bundling and Minification
#if DEBUG
            BundleTable.EnableOptimizations = false;
#else
            BundleTable.EnableOptimizations = true;
#endif
            //Your Bundles...
        }
    }
}

Enable Bundling and Minification - The good way

 

Read More Read More