12/17/2013 4:32:16 PM

Microsoft MVC now has support for CSS and JS bundling and minification. When used locally, the source files will be used. When used in production, minified versions of the files will be used. When multiple files are bundled together, they will be combined into 1 file and then minified. Any changes to the files on the server will force .NET to re-bundle and re-minify.

//1. If necessary, install the Microsoft.AspNet.Web.Optimization package from Nuget

//2. In App_Start folder
BundleConfig.cs file

using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;

namespace YourSite
    public class BundleConfig
        public static void RegisterBundles(BundleCollection bundles)
			//jquery bundled with variables
            //bundles.Add(new ScriptBundle("~/bundles/scripts/jquery").Include(
            //			"~/Scripts/jquery-{version}.js",
            //			"~/Scripts/jquery.*",
            //			"~/Scripts/jquery-ui-{version}.js"));

			//jquery bundled with file individually selected
            bundles.Add(new ScriptBundle("~/bundles/scripts/jquery").Include(
			//css bundle
            bundles.Add(new StyleBundle("~/bundles/css/v1").Include(

//3. In Global.asax
protected virtual void Application_Start()


//4. In View files place CSS and JS - must use the same names as those declared above
@using System.Web.Optimization
<!-- css -->
<!-- js -->