SlideShare a Scribd company logo
Tips and Tricks For Faster ASP.NET and
MVC Web Applications
By Sarvesh Kushwaha
1. Static Resources should be Cacheable ;)
Above code cache all static resources for 365 days.
2. Bundling and Minification
Reduce the amount of data (CSS & JavaScript) sent across the
network using Bundling and Minification in ASP.NET 4.5 .
Bundling is merging all CSS files into one and same for JavaScripts file
.This Reduce the number of requests to server.
Minification is removing blank space b/w words and lines and
more then that ;) .
LINK : HOW TO DO IT
3.Use View State when its necessary
Every control has ViewState in Asp.Net and ViewState is turned on in
ASP.NET by default.
ViewState is an unnecessary overhead for pages that do not need it. As
the ViewState grows larger, it affects the performance of garbage
collection. ViewState gets store in hidden field too many field can make
a web page heavier and will cause rendering problem.
So Disable ViewState for every control, untill you need it (have to keep
data on post backs of a page).
1. You know you don't need ViewState for a textbox control and similar control untill
you are performing textchange_event. So disable it by using EnableViewState=
“false” for each one.
2. Disable ViewState at page level add in page : <%@ Page EnableViewState="false"
%> .
3. Disable ViewState at Application level add in web.config : <pages
enableViewState="false" />.
4. Use Effecting Paging
• Bring small set of data at once ,show them using paging to render the page quickly.
• Large set of data use stored procedure for page index data and filtering .
LINK: HOW TO DO IT
5. URL Compression
Now with IIS 7 we can do HTTP compression of data being send over the
network . Add following Xml snippets in the web.config file under
<system.webserver> node :
<urlCompression doDynamicCompression="true" doStaticCompression="true"
dynamicCompressionBeforeCache="true"/>
• doDynamicCompression tells IIS whether it should compress dynamically
generated content, i.e. content generated by your scripts (ASP, ASP.NET, PHP
…).
• doStaticCompression tells IIS whether to compress static files (PDF, JPEG …)
,those actually exist on the file system.
• dynamicCompressionBeforeCache attribute specifies whether IIS will
dynamically compress content that has not been cached.
6. Use Sprite Images
use sprite images instead of using several images so at one download you can
use several small images .
Now we can make sprite images very easily using Some NUGET packages.
Below are some :
7. Image Optimization
• Normally images take largest percentage (size) in a web page. image
optimization help us to increase performance . Using Asp.net Nuget we can
optimize images :
• Allocate space for image using <height/> and <width/> , it will let page
rendering more quickly .
8. Always Deploy in Release Mode
• At the time of deploying our main concern is performance , Debug Mode
creates .pdb file and take some info generated by JIT to code address mapping
.
• Code is more optimized in Release Mode.
• Less memory is used by the source code at run time in Release Mode.
• Set debug=“false” in web.config for release mode.
9. Use client Side Validation
At max one should use client side validation for application as it gives user a friendly experience
and reduce the over head of post back to the server.Where secuirty is priority use server side
validation .
10. Remove Unnecessary HTTP Headers
The X-AspNet-Version, X-AspNetMvc-Version, X-Powered-By, and Server HTTP headers
provide no direct benefit and unnecessarily used a small amount of bandwidth.
• Removing X-AspNet-Version : Under <System.web> add this <httpRuntime
enableVersionHeader="false"/>
• Removing X-AspNetMvc-Version : Add this in Global.asax.cx file
MvcHandler.DisableMvcResponseHeader = true;
• Remove Server HTTP Header : LINK HOW TO DO IT
• Remove or Edit X-Powered-By : IIS7 Manager > HTTP Response Header > Edit or Remove
11. Pipeline Optimization
• There are many default HttpModule which sit in request pipeline and intercept each and every request.
• Example If you are not using window authentication you don’t need window authentication HttpModule.
Add following code in web.config :
<httpModules>
<!-- Remove unnecessary Http Modules for faster pipeline -->
<remove name="Session" />
<remove name="WindowsAuthentication" />
<remove name="PassportAuthentication" />
<remove name="AnonymousIdentification" />
<remove name="UrlAuthorization" />
<remove name="FileAuthorization" />
</httpModules>
12. Use Content Delivery Network
• Better if you download things from nearest server from your palace .its like
travelling things from one country to another which takes times. If application
has large number of images, CSS, JavaScript sending request for each of them
and downloading them across the world will take significant time.
• Content Delivery Network deal with static cacheable Content .
• Bootsrap Used CDN for his latest release ;)
13. Dispose Objects Manually
• Although Objects will be cleaned up when they are no longer being
used and when the garbage collector sees fit. Always dispose an
object which implements IDisposable ,to do so Use a USING
statement to automatically dispose of an object once your program
leaves the scope of the using statement.
using (SqlConnection cn = new SqlConnection(connectionString))
{
using (SqlCommand cm = new SqlCommand(commandString, cn))
{
cm.ExecuteNonQuery();
}
}
14. Effective use of Jquery AJAX in Asp.ne
• Use ajax to download data asynchronously, which are not needed
immediately like content of Accordion (Collapsed Panel) and tabs.
• Don’t make too much ajax requests
• Use ajax when its needed to load more data when user scrolls,
when user is not scrolling there is no benefit to bring all the data at
once.
15. Do use magic of Asynchronous
Methods
If your page needs to access multiple data sources , then use
asynchronous methods to parallelize access to those sources .
LINK : HOW TO DO IT
16. Turn off Tracing unless until its required because its keep track
of the application's trace and the sequences. Under <system.web>
node write following code:
<trace enabled="false" pageOutput="false" />
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true"/>
17. Instead of Respons.Redirect() use Server.Transfer() when we
want to transfer current page request to another .aspx page on the
same server. it helps to reduce server requests. And optionally give
us value of preserve query string and form controls values .
18. String Management :
• Use += operator or String.Concat() when the number of appends is know and short .
• Use StringBuilder object when number of appends is unknown.
19. Asp .NET literal and label are different
• Literal just show that text they don’t add the extra markup.
• Label add the extra markup <label><label/>.
20. Remove Blank Space and lines from HTML
• Using Regular Expressions in VS2012 remove blank lines from .aspx and HTML
^(?([^rn])s)*r?$r?n
• Use CodeMaid tool to remove spaces and more.
21. Use Performance Tools
Correct code makes good performance
• Backend performance Tools : DotNetMemoryProfiler,
SQLServerProfiler
• Performance Tools :
• Static analysis tool : Yslow
• Run Time Profiler : Speed tracer for chrome, Firebug for firefox, IE
Developer tools
• Others : WebPageTest , Page-analyzer , Pingdom
• Monitoring Tool : Fiddler
Developer Checklist
Caching
Client Side Validation
Use ViewState if needed
Dispose Objects ManuallyCDN
Remove Unneccesary HTTP Headers
Effective Paging URL Compression
Pipeline Optimization
Release Mode
Images Optimization & Sprite Images
Bundling and Minification
Jquery Ajax Async and Await Turn Tracing Off
Sarvesh Kushwaha | | | | | |

More Related Content

PDF
Limiting WIP @ SM Summit_5.17.22
PPTX
Html1
PDF
Intro to html revised2
PDF
Research 101 - Paper Writing with LaTeX
PPTX
Regular expressions
PDF
Lecture 3: Semantic Role Labelling
PPTX
Scaling asp.net websites to millions of users
Limiting WIP @ SM Summit_5.17.22
Html1
Intro to html revised2
Research 101 - Paper Writing with LaTeX
Regular expressions
Lecture 3: Semantic Role Labelling
Scaling asp.net websites to millions of users

Viewers also liked (20)

PPTX
10 performance and scalability secrets of ASP.NET websites
PPTX
ASP.NET MVC Performance
PPT
Four Ways to Improve ASP .NET Performance and Scalability
PPTX
Building Scalable .NET Web Applications
PPTX
Web api scalability and performance
PPT
Updated Mvc Web security updated presentation
PPTX
Architecting ASP.NET MVC Applications
PDF
JavaScript For CSharp Developer
PPTX
Scaling your servers with async and await
ODP
Accelerate your web app with a layer of Varnish
PDF
Performance testing wreaking balls
PPTX
jChaart - Web Dashboard Framework
PDF
OpenROV: Node.js takes a dive into the ocean
PPTX
End to End Security with MVC and Web API
PPTX
Design Practices for a Secure Azure Solution
PDF
Frontend Application Architecture, Patterns, and Workflows
PPTX
AngularJS - Architecture decisions in a large project 
PDF
Business Case for SharePoint and Office 365
PDF
SharePoint Folders vs. Metadata
PDF
SharePoint 5000 Item List view Threshold Checklist and Best Practices
10 performance and scalability secrets of ASP.NET websites
ASP.NET MVC Performance
Four Ways to Improve ASP .NET Performance and Scalability
Building Scalable .NET Web Applications
Web api scalability and performance
Updated Mvc Web security updated presentation
Architecting ASP.NET MVC Applications
JavaScript For CSharp Developer
Scaling your servers with async and await
Accelerate your web app with a layer of Varnish
Performance testing wreaking balls
jChaart - Web Dashboard Framework
OpenROV: Node.js takes a dive into the ocean
End to End Security with MVC and Web API
Design Practices for a Secure Azure Solution
Frontend Application Architecture, Patterns, and Workflows
AngularJS - Architecture decisions in a large project 
Business Case for SharePoint and Office 365
SharePoint Folders vs. Metadata
SharePoint 5000 Item List view Threshold Checklist and Best Practices
Ad

Similar to Tips and Tricks For Faster Asp.NET and MVC Applications (20)

PPTX
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
DOCX
High performance coding practices code project
PDF
How to optimize asp dot-net application
PDF
Asp.Net Tips
PPTX
Asp.net performance
PDF
ASP.NET Scalability - DDD7
PPT
How To Optimize Asp.Net Application ?
PPT
How to optimize asp dot net application ?
PPT
IEEE KUET SPAC presentation
PDF
ASP.NET Scalability - NxtGen Oxford
PPTX
ASP.NET Best Practices - Useful Tips from the Trenches
PDF
7 secrets of performance oriented front end development services
PPT
ASPNET Roadmap
PPT
ASP.NET 4.0 Demo
PPTX
10 tips to make your ASP.NET Apps Faster
PDF
7 Habits of Exceptional Performance
PPTX
Improving web site performance and scalability while saving
PPTX
10 things you can do to speed up your web app today stir trek edition
PPTX
ASP.NET MVC Zero to Hero
PDF
ASP.NET Scalability - VBUG London
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
High performance coding practices code project
How to optimize asp dot-net application
Asp.Net Tips
Asp.net performance
ASP.NET Scalability - DDD7
How To Optimize Asp.Net Application ?
How to optimize asp dot net application ?
IEEE KUET SPAC presentation
ASP.NET Scalability - NxtGen Oxford
ASP.NET Best Practices - Useful Tips from the Trenches
7 secrets of performance oriented front end development services
ASPNET Roadmap
ASP.NET 4.0 Demo
10 tips to make your ASP.NET Apps Faster
7 Habits of Exceptional Performance
Improving web site performance and scalability while saving
10 things you can do to speed up your web app today stir trek edition
ASP.NET MVC Zero to Hero
ASP.NET Scalability - VBUG London
Ad

Recently uploaded (20)

PDF
Getting Started with Data Integration: FME Form 101
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Machine Learning_overview_presentation.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
Getting Started with Data Integration: FME Form 101
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Empathic Computing: Creating Shared Understanding
Machine Learning_overview_presentation.pptx
1. Introduction to Computer Programming.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology

Tips and Tricks For Faster Asp.NET and MVC Applications

  • 1. Tips and Tricks For Faster ASP.NET and MVC Web Applications By Sarvesh Kushwaha
  • 2. 1. Static Resources should be Cacheable ;) Above code cache all static resources for 365 days.
  • 3. 2. Bundling and Minification Reduce the amount of data (CSS & JavaScript) sent across the network using Bundling and Minification in ASP.NET 4.5 . Bundling is merging all CSS files into one and same for JavaScripts file .This Reduce the number of requests to server. Minification is removing blank space b/w words and lines and more then that ;) . LINK : HOW TO DO IT
  • 4. 3.Use View State when its necessary Every control has ViewState in Asp.Net and ViewState is turned on in ASP.NET by default. ViewState is an unnecessary overhead for pages that do not need it. As the ViewState grows larger, it affects the performance of garbage collection. ViewState gets store in hidden field too many field can make a web page heavier and will cause rendering problem. So Disable ViewState for every control, untill you need it (have to keep data on post backs of a page). 1. You know you don't need ViewState for a textbox control and similar control untill you are performing textchange_event. So disable it by using EnableViewState= “false” for each one. 2. Disable ViewState at page level add in page : <%@ Page EnableViewState="false" %> . 3. Disable ViewState at Application level add in web.config : <pages enableViewState="false" />.
  • 5. 4. Use Effecting Paging • Bring small set of data at once ,show them using paging to render the page quickly. • Large set of data use stored procedure for page index data and filtering . LINK: HOW TO DO IT
  • 6. 5. URL Compression Now with IIS 7 we can do HTTP compression of data being send over the network . Add following Xml snippets in the web.config file under <system.webserver> node : <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/> • doDynamicCompression tells IIS whether it should compress dynamically generated content, i.e. content generated by your scripts (ASP, ASP.NET, PHP …). • doStaticCompression tells IIS whether to compress static files (PDF, JPEG …) ,those actually exist on the file system. • dynamicCompressionBeforeCache attribute specifies whether IIS will dynamically compress content that has not been cached.
  • 7. 6. Use Sprite Images use sprite images instead of using several images so at one download you can use several small images . Now we can make sprite images very easily using Some NUGET packages. Below are some :
  • 8. 7. Image Optimization • Normally images take largest percentage (size) in a web page. image optimization help us to increase performance . Using Asp.net Nuget we can optimize images : • Allocate space for image using <height/> and <width/> , it will let page rendering more quickly .
  • 9. 8. Always Deploy in Release Mode • At the time of deploying our main concern is performance , Debug Mode creates .pdb file and take some info generated by JIT to code address mapping . • Code is more optimized in Release Mode. • Less memory is used by the source code at run time in Release Mode. • Set debug=“false” in web.config for release mode.
  • 10. 9. Use client Side Validation At max one should use client side validation for application as it gives user a friendly experience and reduce the over head of post back to the server.Where secuirty is priority use server side validation .
  • 11. 10. Remove Unnecessary HTTP Headers The X-AspNet-Version, X-AspNetMvc-Version, X-Powered-By, and Server HTTP headers provide no direct benefit and unnecessarily used a small amount of bandwidth. • Removing X-AspNet-Version : Under <System.web> add this <httpRuntime enableVersionHeader="false"/> • Removing X-AspNetMvc-Version : Add this in Global.asax.cx file MvcHandler.DisableMvcResponseHeader = true; • Remove Server HTTP Header : LINK HOW TO DO IT • Remove or Edit X-Powered-By : IIS7 Manager > HTTP Response Header > Edit or Remove
  • 12. 11. Pipeline Optimization • There are many default HttpModule which sit in request pipeline and intercept each and every request. • Example If you are not using window authentication you don’t need window authentication HttpModule. Add following code in web.config : <httpModules> <!-- Remove unnecessary Http Modules for faster pipeline --> <remove name="Session" /> <remove name="WindowsAuthentication" /> <remove name="PassportAuthentication" /> <remove name="AnonymousIdentification" /> <remove name="UrlAuthorization" /> <remove name="FileAuthorization" /> </httpModules>
  • 13. 12. Use Content Delivery Network • Better if you download things from nearest server from your palace .its like travelling things from one country to another which takes times. If application has large number of images, CSS, JavaScript sending request for each of them and downloading them across the world will take significant time. • Content Delivery Network deal with static cacheable Content . • Bootsrap Used CDN for his latest release ;)
  • 14. 13. Dispose Objects Manually • Although Objects will be cleaned up when they are no longer being used and when the garbage collector sees fit. Always dispose an object which implements IDisposable ,to do so Use a USING statement to automatically dispose of an object once your program leaves the scope of the using statement. using (SqlConnection cn = new SqlConnection(connectionString)) { using (SqlCommand cm = new SqlCommand(commandString, cn)) { cm.ExecuteNonQuery(); } }
  • 15. 14. Effective use of Jquery AJAX in Asp.ne • Use ajax to download data asynchronously, which are not needed immediately like content of Accordion (Collapsed Panel) and tabs. • Don’t make too much ajax requests • Use ajax when its needed to load more data when user scrolls, when user is not scrolling there is no benefit to bring all the data at once.
  • 16. 15. Do use magic of Asynchronous Methods If your page needs to access multiple data sources , then use asynchronous methods to parallelize access to those sources . LINK : HOW TO DO IT
  • 17. 16. Turn off Tracing unless until its required because its keep track of the application's trace and the sequences. Under <system.web> node write following code: <trace enabled="false" pageOutput="false" /> <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/> 17. Instead of Respons.Redirect() use Server.Transfer() when we want to transfer current page request to another .aspx page on the same server. it helps to reduce server requests. And optionally give us value of preserve query string and form controls values .
  • 18. 18. String Management : • Use += operator or String.Concat() when the number of appends is know and short . • Use StringBuilder object when number of appends is unknown. 19. Asp .NET literal and label are different • Literal just show that text they don’t add the extra markup. • Label add the extra markup <label><label/>. 20. Remove Blank Space and lines from HTML • Using Regular Expressions in VS2012 remove blank lines from .aspx and HTML ^(?([^rn])s)*r?$r?n • Use CodeMaid tool to remove spaces and more.
  • 19. 21. Use Performance Tools Correct code makes good performance • Backend performance Tools : DotNetMemoryProfiler, SQLServerProfiler • Performance Tools : • Static analysis tool : Yslow • Run Time Profiler : Speed tracer for chrome, Firebug for firefox, IE Developer tools • Others : WebPageTest , Page-analyzer , Pingdom • Monitoring Tool : Fiddler
  • 20. Developer Checklist Caching Client Side Validation Use ViewState if needed Dispose Objects ManuallyCDN Remove Unneccesary HTTP Headers Effective Paging URL Compression Pipeline Optimization Release Mode Images Optimization & Sprite Images Bundling and Minification Jquery Ajax Async and Await Turn Tracing Off
  • 21. Sarvesh Kushwaha | | | | | |