A few months ago I wrote a blog post about how you could improve the performance of your ASP.NET MVC apps using a third party library to compress and combine your CSS and JavaScript resources.
The latest release of ASP.NET (v4.5) comes with its’ own bundling and minification tools.
And the great news is they’re very easy to use.
For example if your layout file contained three CSS and four JavaScript resources
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>@ViewBag.Title
</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/html5reset-1.6.1.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/photoswipe.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/respond.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/klass.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/code.photoswipe-2.1.6.min.js")" type="text/javascript"></script> </head> <body> @RenderBody()
</body> </html> You can bundle and minify CSS and Javascript resources for your ASP.NET mobile apps by using standard HTML like this
or like this using HTML helpers
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>@ViewBag.Title
</title> <link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" /> <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script> </head> <body> @RenderBody()
</body> </html> Note: Scott Gu reckons the helper will probably be called Html.Bundle in the future.
Using HTML helpers gives you the advantage of adding a unqiue hash based upon the contents of the directory structure on the server for the script resource e.g.

ASP.NET will then cache the output for a year which means it will be served from the cache.
Should any files in a resource directory change the generated hash will also change and user will get an updated version of the file.
So how does ASP.NET MVC 4.5 bundling and minification perform?
This is Chrome resource graph for loading the page without any bundling or minification

and here’s the resource graph for a ASP.NET MVC app using the new bundling or minification tools.

The images say it all!