title: Creating and minifying JavaScript dynamically in ASP.NET MVC server-side code
body: <p>I am using a ASP.NET route (to intercept the call to the .js) and controller to generate some JS I want to use on my client. The reason I'm doing this is so as to not have to duplicate id's or constants on the client. Here's the output of my JS:</p>
  
  <pre><code>app.serviceRootURL = 'http://localhost:65211/';  // set in my web.config
  app.ajaxResponseStatuses = [
      { "status":"Success", "id":0 },              // set in my C# DTO
      { "status":"Failure", "id":1 },
  ];
  </code></pre>
  
  <p>First of all, I am not sure if this is the best approach, so other suggestions to doing this would be beneficial.</p>
  
  <p>More importantly though, I'm wondering how I can bundle and minify this. As I understand it, even if I could minify the JS at compile or run-time, minification will change the names of my variables. So in the above JS, <code>app.ajaxResponseStatuses</code> could get changed to <code>a.bc</code>, and then in the actual JS files where I'm trying to access that variable, they could be looking for <code>x.yz</code>.</p>
  
  <ol>
  <li>Can I minify this code and get it to the server?</li>
  <li>Will I still be able to use the above properties in other minified files?</li>
  <li>(bonus points) Is this a good aproach to pass server-side-only values to be used on the client?</li>
  </ol>