Bundle it is used to compress JS and CSS (multiple files can be packaged into a file), and can distinguish between debugging and non-debugging, debugging without compression, in the original way to display, to facilitate the search for problems.
1.BundleConfig Configuration Bundle
Public classBundleconfig {//For more information about bindings, go tohttp://go.microsoft.com/fwlink/?LinkId=301862 Public Static voidregisterbundles (bundlecollection bundles) {//{version} fuzzy match loads all versionsBundles. ADD (NewScriptbundle ("~/bundles/jquery"). Include ("~/scripts/jquery-{version}.js")); Bundles. ADD (NewScriptbundle ("~/bundles/jqueryval"). Include ("~/scripts/jquery.validate*")); Bundles. ADD (NewScriptbundle ("~/bundles/bootstrap"). Include ("~/scripts/bootstrap.js", "~/scripts/respond.js")); Bundles. ADD (NewStylebundle ("~/content/css"). Include ("~/content/bootstrap.css", "~/content/site.css")); //set Enableoptimizations to False for debugging. For more information,//please visithttp://go.microsoft.com/fwlink/?LinkId=301862Bundletable.enableoptimizations =true; } }
2. Ensure that Application_Start is the starting program of the website program has Bundleconfig registration method
protected void Application_Start () { arearegistration.registerallareas (); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (bundletable.bundles); }
3. Configuration
Bundleconfig's Bundletable.enableoptimizations = False, and Web. config <compilation debug= "true" targetframework= "4.5"/> Indicates that the debug state file is not compressed
Bundleconfig bundletable.enableoptimizations = true; and Web. config <compilation debug= "false" targetframework= "4.5 "/> Indicates release state file compression
ASP. NET MVC uses bundles to package compression JS and CSS