Installing Assman for ASP.NET Mvc 2

1. Install the Assman.Mvc2 NuGet package:
Install-Package Assman.Mvc2
2. While Assman ships with a light javascript minifier (JSMin), it does not ship with a css minifier. If you want to enable css minification as well as better js minification, then install the Assman.YuiCompressor NuGet package
Install-Package Assman.YuiCompressor
3. If you are running .NET 3.5, add the following line of code to your routing setup (e.g. in your Global.aspx.cs file):
routes.IgnoreWebResourceRoutes();
Note that the IgnoreWebResourceRoutes extension method requires you to add a "using Assman.Mvc" at the top of the file.
4. Open your site's layout/master page, and add the following inside the <head> element of your page:
@Html.RenderStylesheets()
@Html.RenderScripts("head")
5. Also add the following line right before the closing </body> tag
@Html.RenderScripts()
6. To include a stylesheet on your page, you can place this anywhere in a view or partial view:
@Html.RequireStylesheet("~/path/to/my/stylesheet.css")
To include a script at the bottom of your page (preferred):
@Html.RequireScript("~/path/to/my/script.js")
If you would like an individual script to be included in the head of your page, you can call RequireScript and specify "head" like this:
@Html.RequireScript("~/path/to/my/script.js", "head")
For more info/recomendations on best practices/locations for including scripts, click here

Last edited Jul 4, 2011 at 8:32 PM by andyalm, version 1

Comments

No comments yet.