Home > front end >  Is it possible to include external file in the bundle?
Is it possible to include external file in the bundle?

Time:11-18

So for example instead of this:

bundles.Add(New ScriptBundle("~/bundles/jquery").Include(
                   "~/jquery-2.1.1.min.js"
                   ))

have something like:

bundles.Add(New ScriptBundle("~/bundles/jquery").Include(
                       $"{apiBaseUrl}/jquery-2.1.1.min.js"
                       ))

Provided that api endpoint is hosting that js file, which it is. (api serves like locally hosted cdn).

Right now this fails with:

"Only application relative URLs (~/url) are allowed."

I wonder if there is a way to include the file living outside of the solution at all?

Thanks for any help.

CodePudding user response:

I think you need to modify the code like this.

bundles.UseCdn = true;   //enable CDN support
var jqueryCdnPath = $"{apiBaseUrl}/jquery-2.1.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery", jqueryCdnPath).Include("~/jquery-{version}.js"));

In the code above, jQuery will be requested from the CDN while in release mode and the debug version of jQuery will be fetched locally in debug mode.

More info - Bundling and Minification using CDN

  • Related