Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kieran O'Dwyer 3 posts 73 karma points
    1 week ago
    Kieran O'Dwyer
    0

    Setting up Bundle.config with CDN source with a local fallback

    Hi

    I have followed the Paul Seal approach to this issue (https://codeshare.co.uk/blog/how-to-use-bundling-to-minify-css-and-javascript-in-mvc-and-umbraco/) but having issue's with it.

    If I follow his Umbraco approach to just set up bundling with local files, this works fine but I am hoping to have my files served by CDN with a fallback if this fails.

    At the bottom of his post, it looks like he reverts back to bundling with CDN in a typical MVC approach but this is carried out in the RegisterBundles methods. I have tried to implement this is the ApplicationStarting event but just doesn't work at all. It just loads the local file in release.

    Anyone else had any issues with this type of thing?

  • Shaishav Karnani from digitallymedia.com 330 posts 1536 karma points
    1 week ago
    Shaishav Karnani from digitallymedia.com
    0

    Hi,

    In that case you might need to use to make it work.

    BundleTable.Bundles.UseCdn = true;

    Please try. Hope it helps to solve the issue.

    Cheers,

    Shaishav

  • Kieran O'Dwyer 3 posts 73 karma points
    1 week ago
    Kieran O'Dwyer
    0

    That's was a quick reply! Thanks!

    Sorry to give some perspective, this is what I already have:

        public class Bootstrapper : IApplicationEventHandler
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
    
        }
    
        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            BundleTable.Bundles.UseCdn = true;
    
            var jqueryCdnPath = @"//ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js";
            var jqueryBundle = new ScriptBundle("~/Content/bundles/jquery", jqueryCdnPath).Include("~/Scripts/jquery-3.4.1.js");
            BundleTable.Bundles.Add(jqueryBundle);
        }
    
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
        }
    }
    

    The switch works fine but the fallback doesn't. I'm not sure if I have to perform a separate check in the master template or if this is automated? I've spotted this on Microsoft Docs: https://docs.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification#code-try-6 but this makes me wonder why we include the local path in the script bundle?

  • Kieran O'Dwyer 3 posts 73 karma points
    6 days ago
    Kieran O'Dwyer
    0

    I've cracked it. Just couldn't spot it. I had an 'add trailing slash' rule applied which was causing my fallback to fail.

    <add input="{REQUEST_URI}" pattern="^/umbraco/*" negate="true" />
    <add input="{REQUEST_URI}" pattern="^/bundles/*" negate="true" />
    

    I already had an negation for /umbraco so just added one for my bundles path and it worked.

Please Sign in or register to post replies

Write your reply to:

Draft