Skip to content

MVC 4 EnableDefaultBundles

bUKaneer edited this page May 11, 2012 · 6 revisions

I'm currently working towards integrating this solution in MVC 4 with Visual Studio 11 Beta. If you are also attempting this and migrating from ClientDependency.Dll to out-of-the-box Bundling in MVC 4 read on.

If you enable EnableDefaultBundles in global.asax rather than TemplateBundles files are auto-magically included and minified based on the Content and Script directories - this is awesome because you can simply drop in the files and everything else is done for you.

Having said that the default order in which files are added and minified is based on known libraries then alphabetical file name see "Ordering files in a Bundle" section.

This means that the include order as specified in the MVC 3 version using Client Dependency is not respected.

Original Script List from Max's Code: Html.RequiresJs("FileUpload/tmpl.min.js", "Content", 5); Html.RequiresJs("FileUpload/canvas-to-blob.min.js", "Content", 5); Html.RequiresJs("FileUpload/load-image.min.js", "Content", 5);

Html.RequiresJs("Bootstrap/bootstrap-image-gallery.min.js", "Content", 6);
Html.RequiresJs("Bootstrap/bootstrap.min.js", "Content", 6);

Html.RequiresJs("FileUpload/jquery.iframe-transport.js", "Content", 10);
Html.RequiresJs("FileUpload/jquery.fileupload.js", "Content", 10);
Html.RequiresJs("FileUpload/jquery.fileupload-ip.js", "Content", 20);
Html.RequiresJs("FileUpload/jquery.fileupload-ui.js", "Content", 30);

Html.RequiresJs("FileUpload/locale.js", "Content", 90);
Html.RequiresJs("FileUpload/main.js", "Content", 99);

As a temporary fix (until I post again with a more elegant solution and maybe even a custom bundle) rename the following list of files and all should be well! I've not yet test this but it should work or at the very least point you in the right direction and save you some time hunting down various bits of info!

tmpl.min.js => a-tmpl.min.js

canvas-to-blob.min.js => a-canvas-to-blob.min.js

load-image.min.js => a-load-image.min.js

locale.js => x-locale.js

main.js => z-main.js

Clone this wiki locally