title: How can I specify an explicit ScriptBundle include order?
body: <p>I'm trying out the <a href="http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" rel="noreferrer">MVC4 System.Web.Optimization 1.0 ScriptBundle feature</a>. </p>
  
  <p>I have the following configuration:</p>
  
  <pre><code>public class BundleConfig
  {
      public static void RegisterBundles(BundleCollection bundles)
      {
          // shared scripts
          Bundle canvasScripts =
              new ScriptBundle(BundlePaths.CanvasScripts)
                  .Include("~/Scripts/modernizr-*")
                  .Include("~/Scripts/json2.js")
                  .Include("~/Scripts/columnizer.js")
                  .Include("~/Scripts/jquery.ui.message.min.js")
                  .Include("~/Scripts/Shared/achievements.js")
                  .Include("~/Scripts/Shared/canvas.js");
          bundles.Add(canvasScripts);
      }
  }
  </code></pre>
  
  <p>and the following view:</p>
  
  <pre><code>&lt;script type="text/javascript" src="@Scripts.Url(BundlePaths.CanvasScripts)"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>where <code>BundlePaths.CanvasScripts</code> is <code>"~/bundles/scripts/canvas"</code>. It renders this:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/bundles/scripts/canvas?v=UTH3XqH0UXWjJzi-gtX03eU183BJNpFNg8anioG14_41"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>So far so good, except <code>~/Scripts/Shared/achievements.js</code> is the first script in the bundled source. It depends on every script included before it in the <code>ScriptBundle</code>. <strong>How can I ensure that it honors the order in which I add include statements to the bundle?</strong></p>
  
  <p><strong>Update</strong></p>
  
  <p>This was a relatively new ASP.NET MVC 4 application, but it was referencing the optimization framework pre release package. I removed it and added the RTM package from <a href="http://nuget.org/packages/Microsoft.AspNet.Web.Optimization" rel="noreferrer">http://nuget.org/packages/Microsoft.AspNet.Web.Optimization</a>. With the RTM version with debug=true in web.config, <code>@Scripts.Render("~/bundles/scripts/canvas")</code> renders the individual script tags in the correct order. </p>
  
  <p>With debug=false in web.config, the combined script has the achievements.js script first, but since its a function definition (object constructor) that's called later, it runs without error. Perhaps the minifier is smart enough to figure out dependencies?</p>
  
  <p>I also tried the <code>IBundleOrderer</code> implementation that Darin Dimitrov suggested with RTM with both debug options and it behaved the same.</p>
  
  <p>So the minified version is not in the order I expect, but it works.</p>