UPDATE: After some time the bundling works fine, dont know what it was )
In my BundleConfig.cs I have these bundles defined
public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/vendor").Include( "~/Scripts/jquery-{version}.js", "~/Scripts/bootstrap.js", "~/Scripts/bootstrap-datetimepicker.js", "~/Scripts/es6-shim.js", "~/Scripts/toastr.js", "~/Scripts/angular.js", "~/Scripts/angular-route.js", "~/Scripts/highcharts.src.js", "~/Scripts/highcharts-ng.js", "~/Scripts/angular-block-ui.js", "~/Scripts/angular-translate.js")); bundles.Add(new ScriptBundle("~/bundles/app").Include( "~/Scripts/app/app.js", "~/Scripts/app/directives.js", "~/Scripts/app/translation.js", "~/Scripts/app/data.service.js", "~/Scripts/app/main.controller.js", "~/Scripts/app/parameters.controller.js", "~/Scripts/app/schedules.controller.js", "~/Scripts/app/settings.controller.js", "~/Scripts/app/subscriptions.controller.js")); }
In my Index.cshtml file I have this sequence of adding these bundles
@Scripts.Render("~/bundles/vendor") @Scripts.Render("~/bundles/app")
If in web.config
<compilation debug="true" targetFramework="4.5">
I have correct bundle sequence
If I change debug to false
<compilation debug="false" targetFramework="4.5">
the sequence is broken, and the app doesnt work!
Why is this happening? How to fix?
1 Answers
Answers 1
It's not typical to use more than one Scripts.Render
stuck together in a page where you can merge the scripts into one bundle. Such this may be required when you work with partial/conditional scripts in specific views where we use RenderSection
to meet our purpose.
Your problem comes from the reality which is bundling order is alphabetical for names with wildcards. In your case, app called before vendor.
My first solution is using one Scripts.Render
if it's possible.
Second solution would be to change the place of calling second Scripts.Render
, say, app scripts like using them in the bottom of page or using meta
tags between them (not after the vendor to avoid ordering).
If you want to ensure that scripts are in correct order, please don't use multiple Scripts.Render
. Instead, Configure the ordering for single bundle.
0 comments:
Post a Comment