2

After upgrading to 9.3 from 8.2.3, css (and I assume script) bundling is not working. When I view the page source, it LOOKs like it should be working; I see the css bundle link, but the page is displayed without the styling and when I try to go to the url directly, it gives 404. The same issue applies to script bundling as well. To transition from 8.2.3, I installed a fresh 9.3 copy and applied our update to it.

Here's the line where the bundled css is:

<link href="/bundles/dkg/styles?v=VJ7wdTUwgYwRwofmoFSeVOVnogFiB0FfKncSPbWvPII1" rel="stylesheet"/>

Going directly to the url gives me a page not found.

Here's the code for my RegisterBundles.cs:

using Sitecore.Pipelines;
using System.Web.Optimization;

namespace Dkg.Web.App_Start
{
    public class RegisterBundles
    {
        public void Process(PipelineArgs args)
        {
#if DEBUG
            BundleTable.EnableOptimizations = false;
#endif

            var bundles = BundleTable.Bundles;

            bundles.Add(new StyleBundle("~/bundles/dkg/styles")
                .Include("~/Content/Lib/owl-carousel/owl.carousel.css", new CssRewriteUrlTransform())
                .Include("~/Content/Lib/owl-carousel/owl.theme.default.css", new CssRewriteUrlTransform())                
                .Include("~/Content/Lib/odometer/odometer-theme-default.css", new CssRewriteUrlTransform())
                .Include("~/Content/Lib/fancybox/jquery.fancybox.css", new CssRewriteUrlTransform())
                .Include("~/Content/Dkg/Styles/dkg.css", new CssRewriteUrlTransform())
                .Include("~/Content/Dkg/Styles/rte.css", new CssRewriteUrlTransform())
            );

            bundles.Add(new ScriptBundle("~/bundles/dkg/scripts")
                .Include("~/Content/Lib/jquery-3.2.1.js")
                .Include("~/Content/Lib/jquery.matchHeight.js")
                .Include("~/Content/Lib/owl-carousel/owl.carousel.js")
                .Include("~/Content/Lib/d3.js")
                .Include("~/Content/Lib/odometer/odometer.js")
                .Include("~/Content/Lib/jquery.waypoints.js")
                .Include("~/Content/Lib/fancybox/jquery.fancybox.js")
                .Include("~/Content/Dkg/Scripts/sitecore-tracking.js")
                .Include("~/Content/Dkg/Scripts/main.js")
                .IncludeDirectory("~/Content/Dkg/Scripts/Components", "*.js", true)
            );
        }
    }
}

And the lines in razor where I load them:

@Styles.Render("~/bundles/dkg/styles")

and

@Scripts.Render("~/bundles/dkg/scripts")

This all worked fine in 8.2.3

2 Answers 2

5

You may need to create a Sitecore patch to ignore the url you're using in your bundle. Without that, Sitecore will try to resolve the url and give 404. You may be having this patch already in Sitecore 8 instance but may have not moved it to new Sitecore 9 instance. Here is an example of the patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" 
xmlns:x="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="IgnoreUrlPrefixes">
        <patch:attribute name="value">/sitecore/default.aspx|/trace.axd|/webresource.axd|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.DialogHandler.aspx|/sitecore/shell/applications/content manager/telerik.web.ui.dialoghandler.aspx|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.SpellCheckHandler.axd|/Telerik.Web.UI.WebResource.axd|/sitecore/admin/upgrade/|/layouts/testing|/bundles/dkg/styles</patch:attribute>
      </setting>
    </settings>
  </sitecore>
</configuration>
1
  • This worked great, thank you!
    – Michael
    Commented Aug 21, 2020 at 19:39
1

You need to hook in to Sitecore 9's Initialize pipeline. Your code seems to suggest, you are relying on App_Start functionality.

Described in more detail here: https://sitecore.stackexchange.com/a/5704/73

In short, create a configuration file to fired your RegisterBundles from.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="MyNamespace.DoSomethingOnStartup, MyAssembley" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>
1
  • We do have this already, though there was no way for you to know that based on my question.
    – Michael
    Commented Aug 21, 2020 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.