ASP.NET web optimization framework with MVC 3 & ASP.NET 4.0 web form
Yesterday, I came across a forum post, where user was facing problem in integrating web optimization framework with MVC 3. So here in this post we will see how we can integrate asp.net web optimization framework with MVC 3 and ASP.NET 4.0 web form application.
Web optimization framework was introduced with MVC 4 and it is included in default MVC 4 template. But we can use it with MVC 3 and ASP.NET 4.0 web form application as well. This is because web optimization framework is built on top of framework 4.0. So here are the steps to use web optimization framework with ASP.NET 4.0 application.
- Create new ASP.NET 4.0 web form or MVC 3 application
- Add web optimization package by issuing following command in Visual studio package manager console
- Now add following code in global.asax.cs
using System.Web.Optimization;
protected void Application_Start()
{
Bundle commonBundle = new ScriptBundle("~/bundle/common")
.Include("~/scripts/common.js");
BundleTable.Bundles.Add(commonBundle);
}
Now build and browse ~/bundle/common and we can see minified version of JavaScript. So this is how we can see default bundle in action with ASP.NET 4.0 and MVC 3 application. You can refer my following post on advanced concept in web optimization framework.
- ASP.NET 4.5 & MVC 4: Revisiting IBundleTransform
- ASP.NET 4.5 & MVC 4 Bundling: Next Approach
- ASP.NET MVC Bundling: Auto sync JavaScript model with MVC model
Check out this index post on ASP.NET Web Optimization Framework (a.k.a Bundling & Minification) to read other post on same.
You can follow me on twitter for latest link and update on ASP.NET & MVC.