views:

122

answers:

3

Hi there,

does anyone know of a good way of doing the following, I need to have available via CSS Links up to 5 CSS files in one, this is pretty bad for trips to the server.. but it helps me keep it organized...

At runtime i automatically consolidate and minify all css files into 1 ...

What i was wondering is how to have links to css files in my source at design time and different at runtime??

Is there some special workaround i can do with <% %> tags?

Thanks

+1  A: 

I use if (false) with HtmlHelper extensions to achieve similar effects. It might look like:

<% if (false) { %>
   <link href="../content/styles/jquery-ui.css" ...
   <link href="../content/styles/site.css" ...
<% } %>
<%= Html.CSS( "jquery-ui.css", "site.css", ... ) %>
tvanfosson
if (false) = execute at design i.e. get all the css for designing in vs.... and then at runtime its not rendered? -- THanks for the reply!
mark smith
Yes. The code block is not executed in design mode but the links are. At runtime if (false) avoids including the links since the test fails.
tvanfosson
+1  A: 

You can try the following in your view or master page:

1) Leave the min'ed CSS links in as they are

2) Use this conditional block to include the CSS files directly as needed for design time:

<% if (this.DesignMode) { %>
 <link rel="stylesheet" type="text/stylesheet" href="css/styles.css" />
<% } %>
HackedByChinese
A: 

You could have one link to the combined file in your HTML and use a build event to combine your separate ones in to the one file. That way, during dev you always see your neat separate files but the designer (and at runtime) will always see the combined file. The designer doesn't care of there is one or 5 files but you do. This way you don't have to do any conditional design-time only logic and your code will be cleaner.

Matthew