0

I have different css files depending on the browser and device. One bundling approach would be to register each combo "phone.ie", "desktop.ie", "phone.chrome", etc. and have the Render method string.format for the right bundle ("~/content/{0}.{1}", device, browser). This would work, but there's a lot more maintenance involved than should be necessary. Additional css files would mean registering a bunch more bundles.

What would be really cool is if I could register a single bundle:

        bundles.Add(new StyleBundle("~/content/css")
            .Include("~/content/css/styles.{device}.{browser}.css"));

and render simply

@Styles.Render("~/content/css")

Where {device} and {browser} is a placeholder for a runtime variable. How could I go about doing this? There is the {version} placeholder used for jQuery bundles, but doesn't seem very extendable for custom values.

Would be neat to maybe feed the render a dictionary

@Styles.Render("~/content/css", new { device = runtimeDevice, browser = runtimeBrowser })
Eilon
  • 25,582
  • 3
  • 84
  • 102
Levitikon
  • 7,749
  • 9
  • 56
  • 74
  • As an aside, why are you trying to serve different CSS to different browsers? It's going against the direction the industry is going. – Mister Epic Jun 11 '14 at 17:28
  • I know @ChrisHardie, it's just what we got. Doesn't mean I gotta like it. Definitely have plans to migrate to something better in the future. – Levitikon Jun 11 '14 at 17:50

1 Answers1

0

There is no built-in support for custom tokens in ASP.NET Bundling and Optimization. I recommend writing a custom extension method such as bundles.AddFormattedBundle(...) that takes the required parameters and does its own substitution. This would all be custom code you'd have to write.

To file a suggestion on ASP.NET Bundling and Optimization you can check out the site: https://aspnetoptimization.codeplex.com/workitem/list/basic

Eilon
  • 25,582
  • 3
  • 84
  • 102