stylesumbracopublishbundlesoptimus

Publishing Umbraco site, bundles doesn't work


I have a website made in Umbraco connected to Visual Studio 2012. When I start the project (F5) it looks like it should with CSS and jQuery. In this project we use bundles.

When I publish my website, the bundles can't be found.
"Failed to load resource: the server responded with a status of 404 (Not Found) http://mywebsite.local/bundles/styles" When I look in the console (on my browser) I can find the folder bundles, and the file style. But it is empty.
But on the local site, there is CSS in the style file.

What am I doing wrong? I mean, it's the same code? It's like somewhere on the way half of my code just disappears. I'm also using Optimus as a package to Umbraco, but it doesn't seem to make any difference.

Here's my BundleConfig:

  public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new StyleBundle("~/bundles/custom/css").Include(
            "~/css/MasterStyle.css",
            "~/css/TopMenu.css",
            "~/css/SmallImages.css",
            "~/css/SideMenu.css",
            "~/css/Footer.css",
            "~/css/Support.css",
            "~/css/Highlight.css"));

        bundles.Add(new ScriptBundle("~/bundles/js/jquery").Include(
            "~/scripts/jquery-{version}.js",
            "~/scripts/jquery-ui-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap/js").Include(
            "~/scripts/bootstrap.js"
            ));

        bundles.Add(new ScriptBundle("~/bundles/js").Include(
            "~/scripts/TopMenu.js",
            "~/scripts/Master.js"));


        LogHelper.Info<string>("Bundles Loaded");

        //Comment this out to control this setting via web.config compilation debug attribute
        BundleTable.EnableOptimizations = true;
    }

My Global.Asax (I have not written this, and definitely not sure if this is correct)

  <script runat="server">
 void Application_Start()
{
  BundleConfig.RegisterBundles(BundleTable.Bundles);
 }

  </script>

UPDATE: Check the correct marked answer, I solved it by following that tutorial and used the code that was posted in the answer. I also noticed a minor error in my bundle.config (that I had checked before so that wasn't the main problem). In my "bundles.Add(new StyleBundle("~/bundles/custom/css")" I have wrong path, for me it should be "~/bundles/styles" instead. And the combination of all this, made it work!


Solution

  • Assuming you're using Umbraco 6 or 7, you could follow the gist here: How to use ASP.NET Bundling and Minifications in Umbraco

    However, you should use an ApplicationEventHandler derived class so that you can register them on startup instead of trying to create your own Global.asax.cs class (this is now the recommended way of doing this sort of thing with Umbraco):

    public class ArticleEventHandler : Umbraco.Core.ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
    

    An alternative to Bundling is to use the ClientDependency package that comes bundled with Umbraco. I can elaborate on that if you need me to, however there are plenty of examples and documentation on that out there.