using System.Web; using System.Web.Optimization; namespace MvcApp { public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery", "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js").Include("~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/bootstrap","https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js").Include("~/Scripts/bootstrap.js")); bundles.Add(new StyleBundle("~/Content/css", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css").Include("~/Content/bootstrap.css")); BundleTable.EnableOptimizations = true; bundles.UseCdn = true; } } }
Many developers do not understand that there is an overload for the constructor of the ScriptBundle and StyleBundle classes, which takes two string parameters, for example, for ScriptBundle it will be ScriptBundle (string, string) and for StyleBundle it will be StyleBundle (string, string). The first parameter is the virtual path, and the second parameter is cdnPath.
We can ask ourselves if it takes two parameters, how does MVC know which one to use? Well, the cdn location is only used when the BundleTable.EnableOptimizations property is set to true.
Setting the EnableOptimization property to true tells MVC to use a mini version of the file instead of the regular version.
If this property is set to true and the cdn path is present, MVC will use the cdn path instead of the local virtual path.
There is another property that you must set to true, and that is bundles.UseCdn.
This tells MVC to use the cdn location instead of the local version. If the BundleTable.EnableOptimization parameter is set to false, then the local version is automatically used as a rollback, because the cdn version is a shortened version .
Read this blog to understand what you think:
http://www.techjunkieblog.com/2015/06/aspnet-mvc-5-configure-bundleconfig.html
Vijay maheriya
source share