Bundling and Minification in asp.net mvc

  By Junaid A   Posted on April-10-2018   722


Bundling and Minification in asp.net mvc

a) Bundling allow to load more than one file in one request
b) Minification remove unnecessary white space and comments and shortening variable names to one character.

in App_Start\BundleConfig.cs add following function

public static void RegisterBundles(BundleCollection bundles)

 bundles.Add(new StyleBundle("~/Common/css/min/tcgrid").Include("~/Common/css/tcgrid.css"));

ScriptBundle scriptBndl = new ScriptBundle("~/bundles/bootstrap");         
    bundles.Add(new ScriptBundle("~/bundles/scripts").IncludeDirectory("~/Scripts/","*.js",true));
BundleTable.EnableOptimizations = true;

 in Global.asax on  Application_Start event

public class MvcApplication : System.Web.HttpApplication
    protected void Application_Start()

The script bundles can be included using static Scripts class. Use Scripts.Render() method to include specified script bundle at runtime.

in head of page we can as


Note!! in web.config dont forget to set debug=false  below

    <!--<sessionState mode="InProc" timeout="60"></sessionState> -->
    <!--Session will be time out after 60 minutes -->
    <sessionState mode="InProc" cookieless="false" timeout="60"/>
    <compilation debug="true" targetFramework="4.5"/>


Ref:  https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification
above are the steps how we can use bundling and minification in asp.net mvc

By  asifjans    10-Apr-2018 Views  722

You may also read following recent Post

Item Image
What are 3 C
Item Image
what is .net
Submit Post - Article - Ask a Question - Ask an Interview Question - Submit Useful Links