Reputation: 13775
Is it possible to add or remove scripts from a bundle based on the debug setting of the application?
I.e. Given a bundle definition of-
var jQueryBundle = new ScriptBundle("~/js/main").Include(
"~/Scripts/jquery-1.{version}.js",
"~/Scripts/jquery-migrate-{version}.js",
"~/Scripts/script.js");
Remove the jquery-migrate reference when the site is not running in a debug profile, or conversely add it under debug.
Nb. I actually came up with a solution to this whilst formulating the question, I have tested it and it seems to work. I have answered it but left it unaccepted for now should a better solution present. In the mean time the answer will at least now be available for reference should anyone want to make use of it.
Upvotes: 2
Views: 1142
Reputation: 13775
I actually came up with an answer to this whilst writing out the question. Since I hadn't been able to find an answer through searching I decided to post the question anyway and answer it - both so it is available as reference for anyone else wanting to do the same thing, and to get feedback from wiser minds than mine if this the most performant way of achieving this - or even a sensible thing to do.
var jQueryBundle = new ScriptBundle("~/js/main").Include(
"~/Scripts/jquery-1.{version}.js",
"~/Scripts/script.js");
if (HttpContext.Current.IsDebuggingEnabled)
{
jQueryBundle.Include("~/Scripts/jquery-migrate-{version}.js");
}
bundles.Add(jQueryBundle);
I have tested this and whilst debugging the script is listed (I have retained the defaults of bundling and minification left off in debug mode) and whilst running normally the contents of the migration script were not in the combined minified script. Over the next couple of days I will profile this to compare to "vanilla" bundling to see what (if any) performance impact this has on application start.
Upvotes: 4