MVC.Net Cdn calls fallback anyway

I am using MVC.Net pooling and minification for now. When I load my page that displays the package (for my example, I am using JQuery one), both the CDN and the backup are requested by the browser, making 2 requests on my web server. The server is expected to receive ~ 2000 bpm, so if I can cut my script requests in half, that would be very cool. So my question is, why is the backup request being requested by the browser and how can I prevent it?

Here is my BundleConfig

     BundleTable.EnableOptimizations = true;
     bundles.UseCdn = true;
     var bundle = new ScriptBundle("~/bundles/JQueryCore", "//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js")
     {
        CdnFallbackExpression = "window.jquery"
     };

     bundle.Include("~/Scripts/JQuery/jquery-2.1.1.js");
     bundles.Add(bundle);

      

In mine .cshtml

I call my script@Scripts.Render("~/bundles/JQueryCore")

The generated html looks like this:

<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js"></script>
<script>(window.jquery)||document.write('<script src="/bundles/JQueryCore"><\/script>');</script>

      

+3


source to share


1 answer


CdnFallbackExpression

must match the library under test; window.jquery

disconnected from my letter. Try:

jqueryBundle.CdnFallbackExpression = "window.jQuery"; // note 'Q'.

      



This will fix the inline test (and therefore prevent the local script from being called).

+2


source







All Articles