title: What is the best practice to include js/css files in an enterprise application framework?
body: <p>I am working on an enterprise application development in ASP.NET MVC3. Of-course I have different master layouts and multiple views. </p>
  
  <p><strong>My concerns</strong></p>
  
  <ul>
  <li>Including all js/css files in master layout might affect the performance of the page</li>
  <li>Including the files in views (where it is required) are creating duplicate references (kick-off jquery/other libraries)</li>
  <li>More the references, the more the back&amp;forth requests between client and server - which in turn affect the performance of the output page</li>
  </ul>
  
  <p><strong>My Thoughts</strong></p>
  
  <ol>
  <li>Create a custom list of required resources and store it in ViewBag. Let the master layout refer this object to include the js/css files</li>
  <li>Or add the link referring an action with some key (an unique value to identify the page being rendered) and dynamically generate an output with all required resources as a single response. And cache the output (inmem/staticfile) with the unique key for succeeding requests. A kind of custom resource bundling.</li>
  </ol>
  
  <p>Please share your ideas, any thoughts and suggestions are welcome! </p>
  
  <blockquote>
    <p>EDIT: Sep.17.2012</p>
  </blockquote>
  
  <p>Below answers are more talking about optimization techniques in web application development world - appreciating those answers.</p>
  
  <p>I would like to discuss from an architectural perspective, focusing on creating a dynamic resource collection required by the page being rendered.</p>
  
  <p>For example, in specific views I would like to use jQuery UI which requires jquery-ui-1.8.11.min.js, and in certain views I would like to use MVC3 ajax which requires MicrosoftMvcAjax.js and jquery.unobtrusive-ajax.min.js</p>
  
  <p>I don't want to include permanent reference in master layout, which will result in loading these js for all views. Rather I would like to include the js files dynamic during runtime.</p>
  
  <p>Hope this might have added clarity!</p>
  
  <p>Thanks for the help - Vinod</p>