1

i have the following bunlde inside my asp.net mvc5 web application:-

bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/style.css",
                      "~/Content/touchTouch.css",
                      "~/fonts/font-awesome.css"));

now will this always render the style.css after the bootstrap.css ? or this is not guaranteed ? if the order is not guaranteed in the above code then how i can control the order of the css and script files inside the bundle ?

John John
  • 1
  • 72
  • 238
  • 501

2 Answers2

2

No. I't won't always render style.css after the bootstrap.css.

If you want ordering, you have to make this (for scripts) and this (for CSS files) change to specifically give them an order.

I understand the links are old (from 2012), but I have used that with success in ASP .NET MVC 5.

Community
  • 1
  • 1
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73
  • but the link you provide is written in august 2012 ,, so is this still the case in mvc 5.2 ? – John John Sep 02 '15 at 01:13
  • now instead of writing new IbundleOrder class , let say i explicitly use the .include to include the css and scripts file one by one as follow "Bundle canvasScripts = new ScriptBundle("~/bundles/scripts/canvas") .Include("~/Scripts/modernizr-*") .Include("~/Scripts/Shared/achievements.js") .Include("~/Scripts/Shared/canvas.js"); bundles.Add(canvasScripts); " will this guarantee the order ? – John John Sep 02 '15 at 01:19
  • the order of the different bundles are not guaranteed either. But, if different bundles have dependencies among each other, doesn't that mean that they should be in the same bundle? Usually, different bundles don't depend on each other. Unless they are external reference libraries like JQuery. – Cacho Santa Sep 02 '15 at 01:21
  • 1
    but the accepted answer inside this link http://stackoverflow.com/questions/11979718/how-can-i-specify-an-explicit-scriptbundle-include-order/11981271#11981271 is using .Include explicitly at each of the scripts files one by one, and they said that when using .Include explicitly then the order will be as defined inside the ScriptBundle ... is this correct or i did not get the point correctly ..? – John John Sep 02 '15 at 01:25
  • ooh, yes, you are correct! I thought we were talking about rendering multiple bundles. – Cacho Santa Sep 02 '15 at 01:27
  • but as i know if i define 2 bundles inside the _layout view such as "@Scripts.Render("~/bundles/modernizr") @Scripts.Render("~/bundles/jquery")" then it is guaranteed that the modernizr bundle will always run first ,, is this correct ? or not ? – John John Sep 02 '15 at 01:29
  • yes, as long as both bundles are using .Include explicitly. – Cacho Santa Sep 02 '15 at 01:31
  • not sure this is correct 100%.. let say i have the following inside my _layout view ""@Scripts.Render("~/bundles/modernizr") @Scripts.Render("~/bundles/jquery")"" ... and the "~/bundles/modernizr" do not use explicit .Include() while the "~/bundles/jquery" uses .include() explicitly ,, then i think that all the scripts inside ~/bundles/modernizr will always be executed before the ~/bundles/jquery scripts regardless if they uses .Include() or not ??? – John John Sep 02 '15 at 01:37
0

ASP.NET MVC has a default order for certain files. For ex, it tries to load jQuery first. You can clear up that list this way:

bundles.FileSetOrderList.Clear();

That worked for me. If it doesn't work for you, you can explicitly indicate the order in which files should be processed in your bundles:

bundles.FileSetOrderList.Clear();
BundleFileSetOrdering ordering = new BundleFileSetOrdering("custom order");
ordering.Files.Add("jquery.js");
bundles.FileSetOrderList.Add(ordering);
Francisco Goldenstein
  • 13,299
  • 7
  • 58
  • 74