include files dynamically

Jul 11, 2009 at 4:38 PM

Is there a posibility to inject the JS and CSS files dynamically? I'm having an application that exposes JS files only on some pages.

 

 

Aug 21, 2009 at 7:51 PM

extending my question about configuration i've decided to fork this project and include some of my own ideas, which include your request. im able to create different groups of files and reference them by a group name. variables are possible too

Example:

<stylesheets>
   <group name="default">
      <file path="~/file1.css" />
   </group>
   <group name="debate" inherits="default">
      <file path="~/debate.css" />
      <file path="~/$(var1)/file.css" />
   </group>
</stylesheets>

and this is of course possible with javascripts too. in the hml you reference the group like this

css.axd/debate/hey (hey will be var1)

Aug 21, 2009 at 8:06 PM

of course this isnt 100% dynamic since you still have to create the groups in the config. but being able to inherit from a default group i find it more flexible and encouraghing to create different groups for every specific type of pages your site has.

I don't use MVC but Webforms for developing and in my Page Base Class i've simply included two properties, StylesheetGroup and JavascriptGroup, so at any point from anywhere i can instruct my page to use for instance JavascriptGroup = "debate", and when the page renders the <style> tag for javascript it points to js.axd/debate. this way you can have all the standard css and js, and on some pages you can override this.

Aug 21, 2009 at 10:39 PM

lets see if i got your request right this time :) with my library you are able to reference a single file without defining it in a resource set first

So this is perfectly legal: js.axd/js/myfile.js and css.axd/css/skin/module/file.css - these will be packed, minified, cached and so on just as was it a resource set.

Take a look at my library here http://cssandjscombiner.codeplex.com

Coordinator
Oct 29, 2009 at 5:48 PM

@razvantim: for this I would suggest creating separate resource sets and linked them as necessary to page.  Does that work or are you looking for s/t else?

Mar 27, 2010 at 7:54 AM
Edited Mar 27, 2010 at 8:02 AM

I second this request.  If one has a large site, managing the config file will become quickly out of hand.  I'm talking about a large group of developers on a very large site.  Some of them are not even developers (i.e. creative / designers).  It'd be much easier to tell those designers to include js/css by something like Html.IncludeJs("abc.js, xyz.js, etc") rather than having to train them to update an xml config (that may get overridden by another guy).  This feature - I believe - is built in with Ruby on Rails.

Coordinator
Mar 30, 2010 at 3:24 PM

@bhoang: thanks for your suggestion.  I'll think about adding object model support for Combres configuration (as opposed to XML, which is the only way now).  I've added a tracking ticket here for further discussion & update.