ASP. NET MVC uses bundles to package compression JS and CSS

Source: Internet
Author: User

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 to         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 visit =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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.