I use MVC.Net bundling and minification at the moment. When I load my page which renders a bundle (For my example I'm using JQuery's one), both the CDN and the fallback are requested by the browser, which makes 2 requests to my web server. The server is expected to receive ~2000 hits per minutes so if I can reduce my scripts requests by half it would be pretty great. So my question is : Why does the fallback is 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 my .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>