0

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?

Bryan Boettcher
  • 4,412
  • 1
  • 28
  • 49

2 Answers2

0

Cassette seems to do this natively. It's not as clean of a syntax as I'd like (I'd prefer being able to reference arbitrary scripts and CSS from pages without having to bundle them) but it does work.

Bryan Boettcher
  • 4,412
  • 1
  • 28
  • 49
0

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).

Community
  • 1
  • 1
AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • I don't care what bundle it gets added to. I am referencing the large CSS and JavaScript files from CDNs and overriding what I need locally. My changes are small. – Bryan Boettcher Jan 24 '14 at 20:58
  • OK I think if you look at that issue it is pretty close to what you're looking for, though it does create a bundle per combination of inputs in an attempt to maximize what browsers can cache. That is very much a work in progress so if you'd like to join the discussion I'm sure your input would help. – AlexCuse Jan 27 '14 at 00:08
  • Well, it's not the answer I was looking for, but it is the answer. Thanks. – Bryan Boettcher Jan 27 '14 at 17:27
  • I am still pretty much in the dark about how AssMan works but will read up on it some. If the only difference is that you want a single bundle per parent page, I think we could make that a configuration option. – AlexCuse Jan 27 '14 at 18:42