Using ASP.NET bundle in Umbraco v8
2 min readJan 20, 2021
This is an update of Quang Phan’s instructions.
1. Install Optimization packages
Open package manager console then enter the script below to install the package:
install-package Microsoft.AspNet.Web.Optimization
2. Add register bundles
Create a BundleConfig
class inside App_Start
folder:
using System.Web.Optimization;
namespace UmbracoPOC.App_Start
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
//Scripts
bundles.Add(new ScriptBundle("~/bundles/jqueryDataTables").Include(
"~/Scripts/jquery.dataTables.js",
"~/Scripts/jquery.dataTables.yadcf.js"
));
//CSS
bundles.Add(new StyleBundle("~/bundles/styles").Include(
"~/path/to/bootstrap.css",
// many here
"~/path/to/styles.css"
));
}
}
}
3. Call the bundle registration
Create a Composer to run at startup:
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Composing;
using System.Web.Optimization;
using UmbracoPOC.App_Start;
namespace UmbracoPOC
{
public class LoadBundles : IUserComposer
{
public void Compose(Composition composition)
{…