Starting with MVC4, we found that Global.asax was optimized in the project to move the code originally used in MVC3 to the "App_start" folder, and Global.asax was only responsible for initializing it. The Bundleconfig class has a function of a bull x: Merge and Compress. It is troublesome to think of the tool compression and manual merging when I do the ASP. The bundleconfig can greatly improve work efficiency and project performance.
First, the basic use
1.1. Initialization of Global.asax files
protected void Application_Start () { routeconfig.registerroutes (routetable.routes); }
1.2. bundleconfig Binding Compressed file
public class Bundleconfig { //For more information about bundling, please visit http://go.microsoft.com/fwlink/? linkid=254725 public static void Registerbundles (Bundlecollection bundles) { bundles. ADD (New Scriptbundle ("~/bundles/jquery"). Include ( "~/content/scripts/jquery-{version}.js" )); Bundles. ADD (New Scriptbundle ("~/content/scripts/toojs"). Include ( "~/content/scripts/jquery.cookie.js", "~/content/scripts/footer.js" ));
1.3. Display in view
@Styles. Render ("~/content/css/common") //single-style binding @scripts.render ("~/bundles/jquery", "~/content/scripts/ Toojs "," ~/content/sctipts/bootstraptjs ") //Multiple JS bindings
1.4. Configuration of Web. config
<system.web> <compilation debug= "true" targetframework= "4.5"/>
Debug= "False" when the compression is enabled
Second, the effect explanation
When compression is enabled, open Firebug you will see
Multiple files are merged together, the file format is removed, and the resulting compression increases the load time of the file.
I think there's another very smart benefit: support for regular matching files
*\{version} Two is a good match, in the actual project, in the style iterative development, stlye.1.0.css,stlye.1.1.css,stlye.1.2.css,stlye.1.3.css ... The pattern accumulates, the path only writes ~/content/stlye.*.css to be possible.
In the JS development time changed a lot of time Bug,js have version update: Script.1.0.js,script.1.0.min.js,script.1.1.js,script.1.1.min.js will use to the latest version, with {version} The latest files will be taken in debug mode, and the latest min will be taken when you publish.
Three, the attention matters:
At first, the name of the virtual path is very strange: ~/bundles/jquery. As follows:
Bundles. ADD (New Scriptbundle ("~/bundles/jquery"). Include (
Bundles. ADD (New Scriptbundle ("~/content/scripts/toojs"). Include (
I began to think: ~/content/scripts is the folder address of the file, followed by casually named, but ~/bundles is what? When we were tracking, we found:
Before the bundles registration has a value, the original system has been defined 7 path identification, it should be used by default. This place has been pit me for a long time, Baidu also no one said ~
Well, that's all, this verse doesn't say the code, that's the new feature under the bundle.