Question

The AspNet.Web.Optimization bundling and minification package supports the use of a CDN and local failover.

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.UseCdn = true;
    BundleTable.EnableOptimizations = true; //force optimization while debugging

    var jquery = new ScriptBundle("~/bundles/jquery", "//ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js").Include(
            "~/Scripts/jquery-{version}.js");
    jquery.CdnFallbackExpression = "window.jQuery";
    bundles.Add(jquery);
    //...
}

All the examples provided that I have found, have focused on using this for jQuery but I am trying to find the appropriate CdnFallbackExpression for failover on the javascript file for Bootstrap when hosted on a CDN.

Anyone found a solution for this?

Was it helpful?

Solution

bootstrap.CdnFallbackExpression = "$.fn.modal";

Checking for the modal function should work, and seems to be the most common method on the interwebs (e.g. how to fallback twitter-bootstrap cdn to local copy).

That should write out something like:

<script>    $.fn.modal || document.write('<script src="Script/bootstrap.min.js"><script>')</script>

If you also wanted something for css, then you could do it manually. This snippet might help: https://github.com/MaxCDN/bootstrap-cdn/issues/110

Or, there's this github project: https://github.com/EmberConsultingGroup/StyleBundleFallback

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top