MVC Backup CDN for Style Bundle

Is there a built-in way to MVC to specify a CDN backup for stylesheets? I am trying to set up a backup of a jQuery mobile style sheet. Here is my code in the RegisterBundles method:

 var JQMstyleSheet = new StyleBundle("~/JQMstyle", "http://code.jquery.com/mobile/1.3.1/jquery.mobile.structure-1.3.1.min.css").Include("~/theme/jquery.mobile.structure-1.3.1.css"); JQMstyleSheet.CdnFallbackExpression = "window.jQuery.mobile"; bundles.Add(JQMstyleSheet); 

When the page displays this in html:

 <script> (window.jQuery.mobile)||document.write('<script src="/JQMstyle"><\/script>'); </script> 

When a CDN crashes, it does not dynamically add a stylesheet, which is great for javascript files. I think the problem is that it is trying to display the script when it should be style. Is there another fallback property other than CdnFallbackExpression ?

UPDATE

Microsoft docs for System.Web.Optimization.StyleBundle show CdnFallbackExpression as an available property, but the description says: "Gets the script extension displayed by the Scripts helper class ..." http://msdn.microsoft.com/en-us/library/ system.web.optimization.stylebundle (v = vs. 110) .aspx Is this a bug in System.Web.Optimization.StyleBundle ? should this property refer to the helper class Styles ?

+6
source share
1 answer

TL; DR;

Check out my solution, which provides a StyleBundle extension method to solve the problem.

The Bundle Style Return

AND

Yes, there is a bug in the Microsoft ASP.NET Framework Optimization Framework documented here .

The solution is to change CdnFallbackExpression as a javascript function that checks the stylesheet and loads the backup, while ignoring the script from the Optimization platform.

There are several difficult parts, especially checking the loading of a stylesheet when it comes from a different domain, like most CDN sources.

I have a solution on GitHub that you can use until the problem is fixed within the framework; However, I will still follow the tricky part of determining when the stylesheet is loaded.

+10
source

All Articles