Force ASP.Net MVC Bundle to render the javascript files in a certain order
.net-4.0, asp.net, asp.net-mvc-4, bundle, bundling-and-minification
Solution
Write your own orderer as Darin Dimitrov answer in this question: How can I specify an explicit ScriptBundle include order?
public class MyBundleOrderer : IBundleOrderer
{
public virtual IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
{
//any ordering logic here
return files;
}
}
Problem
I am working on an ASP.Net MVC 4 application and using Bundling and minifiction to render styles and script files. I have a script file (File A) that call function in another file (File B) , when I am using `@Scripts.Render()` method it render `link` tag for File A before File B so it fire an error and the script not work correctly. Is there any way to force `@Script.Render()` to render `link` tags in certain order without using separate bundle for each file???? EDIT I am using `IncludeDirectory` method to include all script files in that folder ``` public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/js").IncludeDirectory( "~/Scripts/js", "*.js")); } } ```