Nov 29, 2012

Bundling and Minification in MVC 4 And Website Then Project Solution

11/29/2012 02:25:00 AM

Bundling and Minification in MVC 4 

Bundling: It’s a simple logical group of files that could be referenced by unique name and being loaded with one HTTP requestor.

Minification: It’s a process of removing unnecessary whitespace, line break and comments from code to reduce its size thereby improving load times.



Project Solution:

Tools->Library Package manager->Package Manager console click
bottom below use
PM>Install-Package Microsoft.Web.Optimization –Pre

Support in Bin Files:

Microsoft.system.Web.Optimazation
Microsoft.Web.infrastructure
WebGrease

Using Global.asax using Register bundles with Application_Start:


  void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Bundle ins1 = new Bundle("~/Htpage");
        ins1.Include("~/Scripts/jquery-1.4.1-vsdoc.js");
        ins1.Include("~/Scripts/jquery-1.4.1.js");
        ins1.Include("~/Scripts/jquery-1.4.1-min.js");
    }
 
Using Application page using unique name js file using Htpage/Scripts
 
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <%: System.Web.Optimization.Scripts.Render("~/Htpage/Scripts" )%>
     
</head>
 
Website :
 
1.    Add Dll File Microst.Web.optimazation.dll in bin folder.
2.    then global.asax  file to add  global.asax.cs file to needed So Add Global.cs
How can add Global.cs file 
1.    App_data to added the new Class file ,File Name is Global.cs
2.    Add Import package name “Using System.web.optimazation”
3.    class name to add “public class Global:System.Web.HttpApplication”
4.    Add the Application_Start function below item .
5.    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Bundle ins1 = new Bundle("~/Htpage");
           ins1.Include("~/Scripts/jquery-1.4.1-vsdoc.js");
           ins1.Include("~/Scripts/jquery-1.4.1.js");
           ins1.Include("~/Scripts/jquery-1.4.1-min.js");
    }
 
6. Using Application page using unique name js file usingHtpage/Scripts
 
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <%: System.Web.Optimization.Scripts.Render("~/Htpage/Scripts" )%>
     
</head>
 Before And After checking page script size in Firebox 
 
 
 
 
 






 

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

Recent Posts
Popular Articles

 

© 2013 MUNISH ORACLE DBA& .Net Developer. All rights resevered. Designed by Templateism

Back To Top