Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply custom bundle order?

I'm playing around with the new ASP.NET bundling feature and can't seem to get my custom ordering to work. Here are my JS files:

bootstrap.js
bootstrap.min.js
jquery-1.7.2.intellisense.js
jquery-1.7.2.js
jquery-1.7.2.min.js
jquery-ui-1.8.19.js
jquery-ui-1.8.19.min.js
jquery.unobtrusive-ajax.js
jquery.unobtrusive-ajax.min.js

I would like the bundler to output boostrap*.js before all the jQuery files. I understand that internally the bundler will sort jQuery files on top so i tried to overrride the logic without success:

var bootstrapOrdering = new BundleFileSetOrdering("bootstrap");            
bootstrapOrdering.Files.Add("bootstrap*.js");            
bootstrapOrdering.Files.Add("jquery*.js");
BundleTable.Bundles.FileSetOrderList.Add(bootstrapOrdering);

Note: I would prefer to use wildcard if possible to cover all the cases without specifying all the files in code.

Does anyone know i can apply the custom order?

Thanks

like image 592
Fixer Avatar asked Apr 19 '12 04:04

Fixer


1 Answers

You almost had it, the small thing that you missed was just inserting your ordering at the front of the list.

BundleTable.Bundles.FileSetOrderList.Add(bootstrapOrdering);

should be:

BundleTable.Bundles.FileSetOrderList.Insert(0, bootstrapOrdering).

As a result you actually don't need to specify jquery*.js in your ordering, you only need to add your ordering and bootstrap*.js will be prioritized ahead of the built in jquery ordering.

like image 127
Hao Kung Avatar answered Sep 19 '22 08:09

Hao Kung