Mvc4mall Project 4: Using Bundle bundling and compression technology, mvc4bundle

Source: Internet
Author: User

Mvc4mall Project 4: Using Bundle bundling and compression technology, mvc4bundle

From MVC4, we found thatGlobal. asaxThe code used in MVC3 is moved to the [App_Start] folder, while Global. asax is only responsible for initialization. The BundleConfig class has a very powerful function: Merge and compress. It is very troublesome to compress and manually merge ASP. NET files. BundleConfig can greatly improve work efficiency and project performance.

I. Basic usage

1.1. Global. asax file Initialization

  protected void Application_Start()        {            RouteConfig.RegisterRoutes(RouteTable.Routes);        }

1.2 bind BundleConfig to a compressed file

Public class BundleConfig {// For more information about bunddling, visit the 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 ") // bind a single style @ Scripts. Render ("~ /Bundles/jquery ","~ /Content/Scripts/toojs ","~ /Content/Sctipts/bootstraptJs ") // bind multiple JavaScript Codes

1.4. web. config Configuration

<system.web>    <compilation debug="true" targetFramework="4.5"/>
Enable compression when debug = "false"

Ii. effect description

After compression is enabled, open firebug and you will see

Multiple files will be merged together, and the file format will be removed to form compression, improving the file loading time.

I think there is another smart benefit: Regular Expression matching is supported.

* \ {Version} else ...... Mode accumulation, path write only ~ /Content/stlye. *. css.

During JS development, bugs were often changed. JS versions were updated: Script.1.0.js and Script.1.0.min. js, Script.1.1.js, Script.1.1.min. js uses the latest version. In {version} debug mode, the latest file is obtained, and min is used for release.

 

Iii. Notes:

At the beginning, the name of the virtual path was strange :~ /Bundles/jquery. As follows:
 bundles.Add(new ScriptBundle("~/bundles/jquery").Include(    
 bundles.Add(new ScriptBundle("~/Content/Scripts/toojs").Include(

I thought :~ /Content/Scripts is the folder address of the file, which is named after it, ~ /What is bundles? We found that:

The value is available before bundles registration. The system has already defined seven path identifiers, which should be commonly used by default. I 've been stuck in this place for a long time, and no one said About Baidu ~

Okay, that's all. I didn't talk about code in this section, that is to say, the new features bundled.

 

 

 

 


How to Use JQuery UI under ASPNET MVC4 in VS2012

MVC4 comes with jquery ui. Check BundleConfig. is there any ui-related css and js binding in cs, and then check whether there is binding on the page. When running, check whether the source code has read the ui-related css and js and whether the path is correct.


Related Article

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: info-contact@alibabacloud.com 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.