How to add CDN to bundle.config in asp.net web form package

I use asp.net bundling / minification and put everything in bundle.config as follows:

<styleBundle path="~/css/css">
  <include path="~/css/bootstrap.css" />
  <include path="~/css/flexslider.css" />
  <include path="~/css/font-awesome.css" />
  <include path="~/css/Site.css" />
  <include path="~/css/orange.css" />
</styleBundle>

But I would like to use bootstrap.css from the CDN:

//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css

So how can we do this in the bundle.config file?

+5
source share
3 answers

Currently, you cannot mix and match and extract some of the files in your package from an external source, such as cdn. You can download the entire package to CDN and configure assistants to provide a link to the package in CDN, but you cannot include files from external sources, the files must live somewhere that your application can find.

, VirtualPathProvider, CDN , .

+4

, .

, , randomidea.

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    //            "~/Scripts/jquery-{version}.js"));

    bundles.UseCdn = true;   //enable CDN support

    //add link to jquery on the CDN
    var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";

    bundles.Add(new ScriptBundle("~/bundles/jquery",
            jqueryCdnPath).Include(
            "~/Scripts/jquery-{version}.js"));

// Code removed for clarity.
}

CDN, UseCdn true url ScriptBundle. .

, CDN:

    @Scripts.Render("~/bundles/jquery")

    <script type="text/javascript">
        if (typeof jQuery == 'undefined') {
            var e = document.createElement('script');
            e.src = '@Url.Content("~/Scripts/jquery-1.7.1.js")';
            e.type = 'text/javascript';
            document.getElementsByTagName("head")[0].appendChild(e);

        }
    </script> 

, .

0

All Articles