I'm working on an MVC4 site, and I would like to use some resource management software to consolidate & minify JS & CSS (+ less & coffeescript),
SquishIt has all the plugins I want, they're already configured. All the examples show a very simple idea behind SquishIt, which never includes any asset management. It looks like (and the JavaScript model is almost identical):
<html>
<head>
@Html.BundleCss()
.Add("~/Content/first_file.css")
.Add("~/Content/second_file.css")
.Add("~/Content/third_file.css")
.Render()
</head>
What I'm wanting to do is more like this:
_Layout.cshtml:
<html>
<head>
@Html.BundleCss().Render()
</head>
....
App_Start():
Bundle.Css().Add("~/Content/bootstrap.css").Add("~/Content/jquery-ui.css");
_PartialView.cshtml:
@Html.BundleCss().AddString("a:active { color: red }")
The idea behind this is that I would build up the CSS/JS I need as the views recursively render and then the minifier builds, minifies, and caches at the end. AssMan (http://assman.codeplex.com/) does this, but seems less supported and requires more work to get the required minifiers and language support I want.
Ideas, suggestions?
If I'm following your question correctly, I think this issue is about as close as you're going to get (started from this SO thread). I don't really follow though, what bundle should the .AddString call in your example be added to? It looks to me like you are going to end up with a single combined file per view, which is about as bad as you can get from an optimization perspective.
If you read the discussion on that issue and check out the linked commits maybe it will give you some ideas about how to get the functionality you're after (it might actually be the AutoBundler stuff we've implemented, that is available in prerelease now, and will be getting a soft release in the very near future).