Wednesday, January 4, 2017

Part 22 - Style.Render, Script.Render Methods, and BundleConfig.CS File in Asp.net MVC





Why Style.Render() and Script.Render() method are used in layout?

Style.Render()
o   It is used to render the bundle of CSS files defined in Bundleconfig.CS file.
Script.Render() 
o   It is used to render the bundle of Scripts files defined in BundleConfig.CS file.

Style.Render() and Script.Render() generate multiple Style and Script tags for  each item in the CSS bundle and Scripts bundle when optimizations are disabled.

How to enable optimization?

Open Global.asax file and in Application_Start set EnableOptimizations = true , Like in following example 

protected void Application_Start()
        {           
            System.Web.Optimization.BundleTable.EnableOptimizations = true;
        }

 BundleConfig file importance 
o   This file is used to register the css and js so that they can be bundled and minified
o   In Global.ajax the RegisterBundles method is called at the time of application start
o   The BundleConfig file can be found in App_start folder


Sample of BundleConfig file  




All Code Factory

No comments: