Bundling in Umbraco

Bundling in Umbraco

Wednesday, March 30, 2016

Using ASP.NET 4.5 bundling is easy. You create your bundles, add them to the bundle table and request them when needed. Bundling for Umbraco is no different, but there's one gotcha, causing bundle requests to return 404 errors. This is how you get your bundles up and running.

When using ASP.NET 4.5 bundling together with Umbraco, and getting a bundle using its URL, the request is handled by Umbraco. Since you're requesting a bundle, there's no actual content for Umbraco to return and you'll get a 404 error in return.

Umbraco uses what is called reserved paths. When making a request, Umbraco will evaluate the requested path and serve whatever content that matches. When making a request for a reserved path however, Umbraco will let the request pass through, allowing it to be served by another handler - if one exists in the pipeline.

When requesting a bundle, it's expected that the request is handled by the BundleHandler. Umbraco gets in the way, but by adding your bundle path (e.g. ~\Content\Bundles\) to the list of reserved paths, Umbraco will step out of the way and let the request be handled by the BundleHandler.

Reserved paths are set using the umbracoReservedPaths appSettings key in web.config.

But if you're Using Umbraco, why not stick with CDF? CDF is bundled with Umbraco and the two are known to play nice.