c# - Using CDN in ASP.NET MVC bundles -
i read article bundling , monification, specially using cdn, there things unclear me.
having example :
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 jquery on 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 clarity. }
is there possibility use
{version}
format of cdn references, "local" ones?what point of including in bundles minified version of script, jquery-1.7.1.min.js? if not exist? should not search if
.min
file exist and/or generate respectively?
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; } } }
what lot of developers don't realized there overload class constructor of scriptbundle , stylebundle, takes 2 string parameters, example scriptbundle scriptbundle(string, string) , stylebundle stylebundle(string, string). first parameter virtual path , second parameter cdnpath.
we might asking yourself, if takes 2 parameters, how mvc know 1 use? well, cdn location used when bundletable.enableoptimizations property set true.
setting enableoptimization property true tells mvc use use minified version of file instead of regular version.
when property set true, , cdn path present mvc use cdn path instead of local virtual path.
there 1 more property have set true , bundles.usecdn.
tells mvc use cdn location instead of local version. if bundletable.enableoptimization set false, the local version used automatically fall because cdn version minified version.
read blog clear think:
http://www.techjunkieblog.com/2015/06/aspnet-mvc-5-configure-bundleconfig.html
Comments
Post a Comment