First this isn't directly answering your question and won't fit in comments:
"Adding scripts by wildcard defaults to loading them in alphabetical order, which is typically not what you want. CSS and JavaScript files frequently need to be added in a specific (non-alphabetic) order. You can mitigate this risk by adding a custom IBundleOrderer implementation, but explicitly adding each file is less error prone."
REF: ASP.Net Bundling and Minification
In Practice:
This is the "hidden ordering" that is saving me from this wrong ordering of "known libraries".
bundles.Add(new ScriptBundle("~/bundles/sitescripts").Include(
//add my own scripts explicitly
"~/Scripts/bscript.js",
"~/Scripts/zscript.js",
"~/Scripts/ascript.js",
//purposely calling wrong order
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery-{version}.js"
));
In DEBUG Mode, ASP.Net saves me from my error for "known libraries" by ordering them properly. HTML source:
<script src="/Scripts/jquery-2.1.4.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/bscript.js"></script>
<script src="/Scripts/zscript.js"></script>
<script src="/Scripts/ascript.js"></script>
- the correct order is rendered for
jquery and jquery.validate
- my ordering for "my scripts" is untouched, not in any alphabetical order (but jquery is ordered before my scripts - more on this below)
In Production/Live (and oddly enough the behavior is different from DEBUG but is actually what I wanted/expect), "my order" (explicit) is preserved completely and the default ordering of known libraries is in play.
Screenshot of the bundled/minified script, that Chrome dev tools "prettyfied" for readability:
![prettyfied javascript]()
- the order of my scripts are preserved as explicitly added in the
Bundle
- including "known libraries" - they are after my scripts as explicitly added in the
Bundle (this behavior is different from DEBUG however).
- but ASP.net still saves me from my wrong ordering of known libraries (
jquery lib before validate)
As to "why" DEBUG and PRODUCTION differ in behavior (in Debug, known libraries are ordered before my scripts), I don't know and will defer....
Update:
Going back to the link/answer of Hao Kung, it mentions ResetAll(). So using it effectively:
- removes any default ordering
- will follow your explicit order fully (it will not save you from any error)
- consistent behavior in DEBUG and PRODUCTION
So:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.ResetAll(); //does what it says in DEBUG and Production
bundles.Add(new ScriptBundle("~/bundles/sitescripts").Include(
"~/Scripts/bscript.js",
"~/Scripts/zscript.js",
"~/Scripts/ascript.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery-{version}.js"
));
Debug HTML source (fully preserved, no saving for ordering errors):
<script src="/Scripts/bscript.js"></script>
<script src="/Scripts/zscript.js"></script>
<script src="/Scripts/ascript.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery-2.1.4.js"></script>
Production screen shot (prettyfied and already shows the error in validate):
![enter image description here]()
Hth...