private static System.Web.Optimization.Bundle DoCdnFallbackExpress(this System.Web.Optimization.Bundle bundle, string fallback, string className = null, string ruleName = null, string ruleValue = null) { bundle.Include(fallback); fallback = VirtualPathUtility.ToAbsolute(fallback); bundle.CdnFallbackExpression = String.IsNullOrEmpty(className) ? String.Format(@"function() {{ var len = document.styleSheets.length; for (var i = 0; i < len; i++) {{ var sheet = document.styleSheets[i]; if (sheet.href && sheet.href.indexOf('{0}') !== -1) {{ var rules = sheet.rules || sheet.cssRules; if (rules.length <= 0) {{ document.write('<link href=""{1}"" rel=""stylesheet"" type=""text/css"" />'); }} }} }} return true; }}()", bundle.CdnPath, fallback) : String.Format(@"function() {{ var loadFallback, len = document.styleSheets.length; for (var i = 0; i < len; i++) {{ var sheet = document.styleSheets[i]; if (sheet.href && sheet.href.indexOf('{0}') !== -1) {{ var meta = document.createElement('meta'); meta.className = '{2}'; document.head.appendChild(meta); var value = window.getComputedStyle(meta).getPropertyValue('{3}'); document.head.removeChild(meta); if (value !== '{4}') {{ document.write('<link href=""{1}"" rel=""stylesheet"" type=""text/css"" />'); }} }} }} return true; }}()", bundle.CdnPath, fallback, className, ruleName, ruleValue); return(bundle); }