Mvc3 + ef4.1 build a high-performance and Scalable Application System

Source: Internet
Author: User

Solemnly declare that, if quoted, please indicate the source: (original blog Park: Son of Heaven)

Mvc3 + ef4.1 the web application is already a single page framework with excellent performance. Our goal is to build excellent software. Therefore, performance optimization is still needed.

We should consider the following aspects to build a system:

I. Adjust the code structure

The structure provided by Microsoft is straightforward: scripts (JS script), contents (theme and CSS), controller (Controller), models (model), views, etc. Mvc3 does not provide a large number of development components for developers, but provides basic jquery and jquery UI applications. It gives us more freedom to choose the jquery components needed to build our system.

When I was developing this basic business framework, I felt very depressed and tangled. It was not easy to find a suitable component and integrate it into the mvc3 extension container. After one month, I summarized the need to adjust the code structure of the application system:

Mvcapplication

Contents

CSS-------- General style files, such as site.css

Form -------- small icons used in the editing window (save, cancel, delete, etc.), used for source code development, set to not generate content

IMG-------- Use CSS spirits technology to merge images after a thumbnail, for example, toolbar.png

Themes-------- Jquery UI themes, such as base and UI-lightness

Toolbar -------- small toolbar icon used in the List window, used for source code development, set to not generate content

Scripts

Debug-------- JS file when debugging status, for example: jquery-1.6.1.js, jquery-ui.js, set to not generate content

Release-------- JS files released status, all are compressed versions, such as: jquery-1.6.1-min.js, jquery-ui-min.js

Toolkit

Layout -------- page layout, jquery.layout.js?jquery.layout-min.js=layout-default.css, etc.

Menu -------- unlimited multi-level menu, used on the main interface

Timepicker -------- Date and Time Control Based on jquery UI

......

Template-------- Application Template, for example, the template required for exporting the office...

Controllers

Models

Views

Shared-------- Layout View, such as _ footer, _ header, and _ Layout

Include-------- Contains views, such as _ editscript, _ listscript, _ treescript, and _ toolbar.

......

The above is only the code structure of the mvc3 application, and the structure of the application class library. The business of each project is different.

If you have used mvc3 as an application system, you can see that this code structure extends the existing structure.

1) all third-party components are included in the Toolkit directory.

2) The script is split into Debugging and publishing, which requires a lot of JS scripts under a directory to be much refreshed. The setting is correct and runs directly at release without redundant files.

3) multiple views use the same branch view.IncludeView. If there are not many shared Branch views, you can alsoSharedMerge.

4) Add the debugging and release marks based on: Web. config/system. web/compilation. DEBUG = true/false, including the segment view of CSS/JS scripts, and automatically loads the relevant raw/compressed files according to the program status.

Ii. Further optimize the program framework

01) CSS spirits combines small icons into a large image. The background, positioning, and size restrictions are displayed.

The first purpose of merging a thumbnail is to merge at least a dozen toolbar icons and use a large image to Improve the efficiency. However, after trying many times, we are all excited and give up. Why? The reason is that CSS spirits is not used, and the background image is not used.

I have an article about how to use CSS spirits technology and the toolbar. For details, refer to the csdn technical column: mvc3 basic business development framework 0.6.20110530 version Update log (add Date and Time Selection + paging with conditional query + drop-down toolbar ).


The principle is: <A> <span> button text </span> <
/A> the image and text constitute a button as a whole. The image first loads a transparent foreground image and uses the merged large image as the background image (with a pattern), penetrating the transparent foreground image, it looks like
A thumbnail.

CSS spirits technology can also be used in many places: Button icons in the editing window, and the image background on the main interface.

02) compressing CSS and JS scripts

If you have used tools for online compression of CSS and JS scripts, it is not difficult to understand and find many such resources. Make full use of them to save your bandwidth.


Here, provide a suggestion: use Notepad, put jquery. Min. js and jquery-ui.min.js
Content has been copied in, manually delete the line feed, compressed into a row, the merged file name: jquery-1.6.1-ui-1.9m5.min.js, with the appropriate tool to compress the post-life
Name: jquery-1.6.1-ui-1.9m5-min.js, application to your release version of the program, two requests => A request, is not good? If you use
Jquery-ui-custom version with fewer bytes.

If JavaScript files are compressed and cannot run normally, you can clearly tell you that this JS file is not compiled in a standardized way, and it may be caused by the missing ";" at the end of the line!Don't believe it. You can try it! Experiment with bailing. I once found several "omitted" semicolons in a 5-6 thousand lines of code, added them, and compressed them again.

Closure_packer_yui_compiler compresses JavaScript files accurately. It is recommended that JavaScript files be compressed.

Some CSS compression will damage the syntax structure, resulting in abnormal display, you must be careful!

03) use the segment view + ajax to display content first.

If a grid contains a toolbar that requires some CSS + JS file references, we recommend that you use the segment view to include the file and write the header of the layout. The toolbar is extracted as the segment view for future adjustment; the page is extracted as the branch view, and data is updated when pages are turned over.


We recommend that you use the pop-up page editing mode, with the $. Ajax request controller and jquery UI
Dialog shows Ajax content, with a small amount of data and extremely fast display speed. I have made three frameworks: extjs and jquery.
Easyui, mvc3, and mvc3 single-page mode execution speed> = jquery easyui, minimum memory usage, and compatible with IE
9. excellent performance. It is strongly recommended that programmersWebform website ProgramGoMvc3 ApplicationThis is the development trend.

04) prioritize the use of LINQ + ORM

Data-driven programs process databases as the main business. The model-driven program solves the problem from the object-oriented perspective.


There are many ORM implementation methods and tools, and the blog Park has been fighting for time: nhib.pdf and entityframework
Superior or inferior? We do not care about the advantages and disadvantages, who has the highest performance, as long as it is suitable for enough is good. Ef4.1 code is recommended
First is actually a model driver with code priority. Simple and Easy-to-use, it is very suitable for mvc3 applications. It is a subsidiary of Microsoft and has many documents and instances.

I'm afraid we need some of our colleagues to change their mindset: data-driven => model-driven => domain-driven.

The code for accessing dbcontext by using LINQ is very concise and can be learned by those who have used it.

To make it clear how to make good use of the LINQ + ORM is a very complex problem. It is not a clear description of one or more articles.

Iii. High-Performance running Structure

01) use the output cache instead of immediately updating the page content.

For example, if the dynamic menu on the main interface is loaded for the first time after login, it reads data from the database/configuration file, sets the page output cache, and does not need to frequently access the database within 10 minutes.

[Outputcache (duration= 600, location = outputcachelocation. server, varybyparam = "personcode")]
Public jsonresult initmenu (string personcode)

02) compress and clear the output code.

If the output type is text/HTML, and the client browser supports gzip/deflate compression, start data stream compression.

If clear is enabled (default), replace the regular expression <! -- * -->,/**/, //, And other program comments, clear blank before and after carriage return, clear> <blank before and after.

The output of pure HTML + JS scripts is required, without any comments, blank blocks, copyrights, and other additional information. Pay attention to regular expression verification.

03) do not use view engines.

// Remove unnecessary view engines and add only razor
Viewengines. Engines. Clear ();
Viewengines. Engines. Add (New razorviewengine ());

04) solution configuration: release version.

05) automatically load the debugging and running version files.

06) exclude non-published files and set the published files to the generated content.

07) Enable the gzip compression function provided by IIS to compress and cache external CSS and JS files. Data stream compression + IIS compression, including the overall optimization of internal + External scripts.

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.