Created
October 5, 2012 12:15
-
-
Save johnnyreilly/3839486 to your computer and use it in GitHub Desktop.
Using Web Optimization with MVC 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>@ViewBag.Title</title> | |
@Styles.Render("~/Content/css", | |
"~/Content/themes/base/css") | |
@Scripts.Render("~/bundles/modernizr") | |
</head> | |
<body> | |
<div class="page"> | |
<div id="header"> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
<div id="logindisplay"> | |
Welcome <strong>@User.Identity.Name</strong>! | |
</div> | |
<div id="menucontainer"> | |
<ul id="menu"> | |
<li>@Html.ActionLink("Home", "Index", "Home")</li> | |
<li>@Html.ActionLink("About", "About", "Home")</li> | |
</ul> | |
</div> | |
</div> | |
<div id="main"> | |
@RenderBody() | |
</div> | |
<div id="footer"> | |
</div> | |
</div> | |
@Scripts.Render("~/bundles/jquery", | |
"~/bundles/jqueryui", | |
"~/bundles/jqueryval") | |
@RenderSection("scripts", required: false) | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web; | |
using System.Web.Optimization; | |
namespace WebOptimizationWithMvc3.App_Start | |
{ | |
public class BundleConfig | |
{ | |
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 | |
public static void RegisterBundles(BundleCollection bundles) | |
{ | |
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( | |
"~/Scripts/jquery-{version}.js")); | |
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( | |
"~/Scripts/jquery-ui-{version}.js")); | |
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( | |
"~/Scripts/jquery.unobtrusive*", | |
"~/Scripts/jquery.validate*")); | |
// Use the development version of Modernizr to develop with and learn from. Then, when you're | |
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need. | |
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( | |
"~/Scripts/modernizr-*")); | |
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css")); | |
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include( | |
"~/Content/themes/base/jquery.ui.core.css", | |
"~/Content/themes/base/jquery.ui.resizable.css", | |
"~/Content/themes/base/jquery.ui.selectable.css", | |
"~/Content/themes/base/jquery.ui.accordion.css", | |
"~/Content/themes/base/jquery.ui.autocomplete.css", | |
"~/Content/themes/base/jquery.ui.button.css", | |
"~/Content/themes/base/jquery.ui.dialog.css", | |
"~/Content/themes/base/jquery.ui.slider.css", | |
"~/Content/themes/base/jquery.ui.tabs.css", | |
"~/Content/themes/base/jquery.ui.datepicker.css", | |
"~/Content/themes/base/jquery.ui.progressbar.css", | |
"~/Content/themes/base/jquery.ui.theme.css")); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Home Page</title> | |
<link href="/Content/css?v=zA21MEZPkFOTy3OUxWWonyifZGPNxI-SSbBOWkDhsHk1" rel="stylesheet"/> | |
<link href="/Content/themes/base/css?v=myqT7npwmF2ABsuSaHqt8SCvK8UFWpRv7T4M8r3kiK01" rel="stylesheet"/> | |
<script src="/bundles/modernizr?v=QZTpgFA-zRi28FHInjPOp9lXJl6mFGrWHlv3QhMpqSw1"></script> | |
</head> | |
<body> | |
<div class="page"> | |
<div id="header"> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
<div id="logindisplay"> | |
Welcome <strong>LNR\jreilly</strong>! | |
</div> | |
<div id="menucontainer"> | |
<ul id="menu"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/Home/About">About</a></li> | |
</ul> | |
</div> | |
</div> | |
<div id="main"> | |
<h2>Welcome to ASP.NET MVC!</h2> | |
<p> | |
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. | |
</p> | |
</div> | |
<div id="footer"> | |
</div> | |
</div> | |
<script src="/bundles/jquery?v=-3plyJYF8LQ0YVYbKtEZnEbkML7BIL0Iul_dNlwGXq41"></script> | |
<script src="/bundles/jqueryui?v=RuyxWjtbiK02VYPQGF4OyBZcxNB-W9FsvN6HJTZj4NA1"></script> | |
<script src="/bundles/jqueryval?v=E3jxQivD8ilGcNEk6JrH6Jx2wDop7sWW2YKDc6Kq8gY1"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Home Page</title> | |
<link href="/Content/site.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.core.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet"/> | |
<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet"/> | |
<script src="/Scripts/modernizr-2.6.2.js"></script> | |
</head> | |
<body> | |
<div class="page"> | |
<div id="header"> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
<div id="logindisplay"> | |
Welcome <strong>LNR\jreilly</strong>! | |
</div> | |
<div id="menucontainer"> | |
<ul id="menu"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/Home/About">About</a></li> | |
</ul> | |
</div> | |
</div> | |
<div id="main"> | |
<h2>Welcome to ASP.NET MVC!</h2> | |
<p> | |
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. | |
</p> | |
</div> | |
<div id="footer"> | |
</div> | |
</div> | |
<script src="/Scripts/jquery-1.8.2.js"></script> | |
<script src="/Scripts/jquery-ui-1.8.24.js"></script> | |
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script> | |
<script src="/Scripts/jquery.validate.js"></script> | |
<script src="/Scripts/jquery.validate.unobtrusive.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Home Page</title> | |
<link href="/Content/css?v=zA21MEZPkFOTy3OUxWWonyifZGPNxI-SSbBOWkDhsHk1" rel="stylesheet"/> | |
<script src="/bundles/modernizr?v=QZTpgFA-zRi28FHInjPOp9lXJl6mFGrWHlv3QhMpqSw1"></script> | |
</head> | |
<body> | |
<div class="page"> | |
<div id="header"> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
<div id="logindisplay"> | |
Welcome <strong>LNR\jreilly</strong>! | |
</div> | |
<div id="menucontainer"> | |
<ul id="menu"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/Home/About">About</a></li> | |
</ul> | |
</div> | |
</div> | |
<div id="main"> | |
<h2>Welcome to ASP.NET MVC!</h2> | |
<p> | |
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. | |
</p> | |
</div> | |
<div id="footer"> | |
</div> | |
</div> | |
<script src="/bundles/jquery?v=-3plyJYF8LQ0YVYbKtEZnEbkML7BIL0Iul_dNlwGXq41"></script> | |
<script src="/bundles/jqueryui?v=RuyxWjtbiK02VYPQGF4OyBZcxNB-W9FsvN6HJTZj4NA1"></script> | |
<script src="/bundles/jqueryval?v=E3jxQivD8ilGcNEk6JrH6Jx2wDop7sWW2YKDc6Kq8gY1"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Home Page</title> | |
<link href="/Content/site.css" rel="stylesheet"/> | |
<script src="/Scripts/modernizr-2.6.2.js"></script> | |
</head> | |
<body> | |
<div class="page"> | |
<div id="header"> | |
<div id="title"> | |
<h1>My MVC Application</h1> | |
</div> | |
<div id="logindisplay"> | |
Welcome <strong>LNR\jreilly</strong>! | |
</div> | |
<div id="menucontainer"> | |
<ul id="menu"> | |
<li><a href="/">Home</a></li> | |
<li><a href="/Home/About">About</a></li> | |
</ul> | |
</div> | |
</div> | |
<div id="main"> | |
<h2>Welcome to ASP.NET MVC!</h2> | |
<p> | |
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. | |
</p> | |
</div> | |
<div id="footer"> | |
</div> | |
</div> | |
<script src="/Scripts/jquery-1.8.2.js"></script> | |
<script src="/Scripts/jquery-ui-1.8.24.js"></script> | |
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script> | |
<script src="/Scripts/jquery.validate.js"></script> | |
<script src="/Scripts/jquery.validate.unobtrusive.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
using WebOptimizationWithMvc3.App_Start; //NEW MAGIC GOODNESS | |
using System.Web.Optimization; //NEW MAGIC GOODNESS | |
namespace WebOptimizationWithMvc3 | |
{ | |
// Note: For instructions on enabling IIS6 or IIS7 classic mode, | |
// visit http://go.microsoft.com/?LinkId=9394801 | |
public class MvcApplication : System.Web.HttpApplication | |
{ | |
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | |
{ | |
filters.Add(new HandleErrorAttribute()); | |
} | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
routes.MapRoute( | |
"Default", // Route name | |
"{controller}/{action}/{id}", // URL with parameters | |
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults | |
); | |
} | |
protected void Application_Start() | |
{ | |
AreaRegistration.RegisterAllAreas(); | |
RegisterGlobalFilters(GlobalFilters.Filters); | |
RegisterRoutes(RouteTable.Routes); | |
//NEW MAGIC GOODNESS START | |
BundleConfig.RegisterBundles(BundleTable.Bundles); | |
//NEW MAGIC GOODNESS END | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment