Basic use
Global.asax
protected void Application_Start () { bundleconfig.registerbundles (bundletable.bundles); }
Bundleconfig
Public Static voidregisterbundles (bundlecollection bundles) {bundles. ADD (NewScriptbundle ("~/bundles/jquery"). Include ("~/scripts/jquery-{version}.js")); Bundles. ADD (NewScriptbundle ("~/bundles/bootstrap"). Include ("~/scripts/bootstrap.js", "~/scripts/respond.js")); }
View
@Scripts. Render ("~/bundles/jquery") @Scripts. Render("~/ Bundles/bootstrap")
2 ways to enable bundle (merge compression)
in bundleconfig
registerbundles
method Add the following code
public static void Registerbundles (bundlecollection bundles) {bundles. ADD ( new scriptbundle ( " ~/bundles/jquery ). Include ( ~/scripts/jquery-{vers Ion}.js // enable merge compression Bundletable.enableoptimizations = true
Open web.config
The file, set the debug=false
compiled
<system.web> <compilation debug="false" targetframework=" 4.5 " /> </system.web>
Change Effect
The number of requests is reduced after merging, which in contrast increases the loading speed of the page.
?
Precautions
Picture path problem, after merging multiple CSS together, sometimes causes the picture to fail to load
Workaround: Use absolute path for picture
BundleConfig
Compressed files configured in the configuration are A.js (uncompressed versions), and a.min.js files exist in the same directory. When you modify the A.js file, you want to merge the compressed JS file also contains the modified content, but not as we would like, the compressed JS file or reference to the contents of the A.min.js, previously modified does not appear in the compressed JS file. Similarly, CSS is the same.
References
MVC4 script compression and merging of the new features of ASP.
The ASP. NET MVC Bundle uses