Here are some tips:
1- Simplify the page's design
2- Reduce the number of HTTP requests by:
- Minify Javascript and CSS and use bundle:
@Styles.Render("...")
@Scripts.Render("...")
- CSS Sprites: combine your background image into a single image and use the CSS background-image and background-position properties to display the desired image segment.
- Image maps combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it's not recommended.
- Inline images: Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages.
3- Use a Content Delivery Network (CDN)
Deploying your content across multiple, geographically dispersed servers will make your pages load faster from the user's perspective.
4- Use/Add Output Cache: to any frequently request pages
5- Put Stylesheets at the top: While researching performance at Yahoo!, we discovered that moving stylesheets to the document HEAD makes pages appear to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively.
6- Put script at the bottom: The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.
7- Avoid CSS Expression: CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically. They were supported in Internet Explorer starting with version 5, but were deprecated starting with IE8. As an example, the background color could be set to alternate every hour using CSS expressions:
background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );
As shown here, the expression method accepts a JavaScript expression. The CSS property is set to the result of evaluating the JavaScript expression. The expression method is ignored by other browsers, so it is useful for setting properties in Internet Explorer needed to create a consistent experience across browsers.
8- Make Javascript and CSS as external files: Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
9- Remove/avoid duplicate scripts
10- Disable Request Validation : (becareful with XSS- Cross Site Scripting) use client validation instead
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Employee empObj)
{
}
11- Isolate Data Access Logic From the Controller: The Controller in an ASP.NET MVC application should never have the Data Access logic. The Controller in an ASP.NET MVC application is meant to render the appropriate view based on some user interface action. You should make use of Repository Pattern to isolate Data Access Logic from the Controller – you might need dependency injection to inject the appropriate Repository to your controller at runtime.
12- Disabled unused view engines: The more view engines you have registered the longer this will take and since the miss is not cached the process will have to be repeated the next time a page is requested. If you are using only one view engine in your project you should remove the other ones in Global.asax.
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
13- Deploy Production Code in Release Mode: When we develop ASP.NET applications using Visual Studio, the default value for debug attribute is true. These settings will give a poor performance in production if released in the default debug mode. So, never release your website or application with debug mode set to true. It should be set to false in web.config when moving to production.
<compilation debug="false" />
14- Removing unused HTTP Modules in web.config: remove the module that you don't need such as
<httpModules>
<remove name="PassportAuthentication" />
<remove name="Profile" />
<remove name="AnonymousIdentification" />
</httpModules>
REF and Details in:
- http://developer.yahoo.com/performance/rules.html
- http://blogs.msdn.com/b/marcinon/archive/2011/02/07/mvc-performance-tips.aspx
- http://www.codeguru.com/csharp/.net/net_asp/mvc/top-10-asp.net-mvc-best-practices.htm
- http://www.codeproject.com/Articles/41930/How-To-Improve-the-Performance-of-ASP-NET-MVC-Web
1- Simplify the page's design
2- Reduce the number of HTTP requests by:
- Minify Javascript and CSS and use bundle:
@Styles.Render("...")
@Scripts.Render("...")
- CSS Sprites: combine your background image into a single image and use the CSS background-image and background-position properties to display the desired image segment.
- Image maps combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it's not recommended.
- Inline images: Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages.
3- Use a Content Delivery Network (CDN)
Deploying your content across multiple, geographically dispersed servers will make your pages load faster from the user's perspective.
4- Use/Add Output Cache: to any frequently request pages
5- Put Stylesheets at the top: While researching performance at Yahoo!, we discovered that moving stylesheets to the document HEAD makes pages appear to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively.
6- Put script at the bottom: The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.
7- Avoid CSS Expression: CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically. They were supported in Internet Explorer starting with version 5, but were deprecated starting with IE8. As an example, the background color could be set to alternate every hour using CSS expressions:
background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );
As shown here, the expression method accepts a JavaScript expression. The CSS property is set to the result of evaluating the JavaScript expression. The expression method is ignored by other browsers, so it is useful for setting properties in Internet Explorer needed to create a consistent experience across browsers.
8- Make Javascript and CSS as external files: Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
9- Remove/avoid duplicate scripts
10- Disable Request Validation : (becareful with XSS- Cross Site Scripting) use client validation instead
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Employee empObj)
{
}
11- Isolate Data Access Logic From the Controller: The Controller in an ASP.NET MVC application should never have the Data Access logic. The Controller in an ASP.NET MVC application is meant to render the appropriate view based on some user interface action. You should make use of Repository Pattern to isolate Data Access Logic from the Controller – you might need dependency injection to inject the appropriate Repository to your controller at runtime.
12- Disabled unused view engines: The more view engines you have registered the longer this will take and since the miss is not cached the process will have to be repeated the next time a page is requested. If you are using only one view engine in your project you should remove the other ones in Global.asax.
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
13- Deploy Production Code in Release Mode: When we develop ASP.NET applications using Visual Studio, the default value for debug attribute is true. These settings will give a poor performance in production if released in the default debug mode. So, never release your website or application with debug mode set to true. It should be set to false in web.config when moving to production.
<compilation debug="false" />
14- Removing unused HTTP Modules in web.config: remove the module that you don't need such as
<httpModules>
<remove name="PassportAuthentication" />
<remove name="Profile" />
<remove name="AnonymousIdentification" />
</httpModules>
REF and Details in:
- http://developer.yahoo.com/performance/rules.html
- http://blogs.msdn.com/b/marcinon/archive/2011/02/07/mvc-performance-tips.aspx
- http://www.codeguru.com/csharp/.net/net_asp/mvc/top-10-asp.net-mvc-best-practices.htm
- http://www.codeproject.com/Articles/41930/How-To-Improve-the-Performance-of-ASP-NET-MVC-Web
No comments:
Post a Comment