How to Minify and Bundle files in ASP.NET MVC1 min read

How to Minify and Bundle files in ASP.NET MVC1 min read

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
            BundleTable.EnableOptimizations = false;
            BundleTable.EnableOptimizations = true;
            //Your Bundles...

Enable Bundling and Minification - The good way


There is another way by defining a Tag in your Web.config file but it will prevent your app to run in DEBUG mode which is a bad issue in my opinion.

However if you absolutely want to use this second way, here is the snippet:

    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
Enable Bundling and Minification - The bad way


Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *