Reputation: 8903
I understand the principle behind the bundling and minification with mvc4, but I would like to use the basic pre-minified libraries for such items as jquery and other large and common libs.
Thus, in my production version, instead of referencing a bundle like this:
bundles/jquerymobile?v=N1H63GRw6_-3057BORWSW60RX5rLWde08XZf8PiKQaE1
I would prefer to use the standard jquery min version, like this:
jquery-1.8.2.min.js
Then my next step will be to allow replacing these standardized libs with CDN hosted ones, such as the ones that google and other big cdn's make available.
So: two parts to this question:
-How can I instruct the bundler to directly include a pre-minified file, unbundled with others?
-How can I create a link to a CDN hosted version of this file instead of referencing local ones?
Upvotes: 1
Views: 819
Reputation: 20004
Why? If you bundle it with the rest of your scripts it's still minified, and it's one less HTTP request. There is no functional difference if you bundle this script with the others. Bundling it simply reduces HTTP requests (which is probably more important than minifying).
You don't, you include the script on the page like normal. If you want to use the bundler for the sole purposes of minifying your script, then create a separate bundle with just that one script.
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.
}
Upvotes: 1