Reader small image

You're reading from  ASP.NET 8 Best Practices

Product typeBook
Published inDec 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781837632121
Edition1st Edition
Languages
Right arrow
Author (1)
Jonathan R. Danylko
Jonathan R. Danylko
author image
Jonathan R. Danylko

Jonathan "JD" Danylko is an award-winning, full-stack ASP.NET architect. He's used ASP.NET as his primary way to build websites since 2002 and before that, Classic ASP. Jonathan contributes to his blog (DanylkoWeb) on a weekly basis, has built a custom CMS, is a founder of Tuxboard (an open-source ASP.NET dashboard library), has been on various podcasts, and guest posted on the C# Advent Calendar for 6 years. Jonathan has worked in various industries for small, medium, and Fortune 100 companies, but currently works as an Architect at Insight Enterprise. The best way to contact Jonathan is through GitHub, LinkedIn, Twitter, email, or through the website.
Read more about Jonathan R. Danylko

Right arrow

Push Your Application with Performance

With each new release of ASP.NET, the ASP.NET team continues to make performance a priority. When ASP.NET Core introduced a different way of building web applications with streamlined enhancements (including middleware and Razor Pages) the focus was continually on improving the C# language as well. These technologies are what give ASP.NET its spark and speed.

ASP.NET is cross-platform, has built-in support for dependency injection, is open source, and is one of the fastest-performing frameworks in the industry.

While this is an ASP.NET book with a chapter on performance, there will be additional aspects of web development that are equally as important. We’ll stay focused on ASP.NET and C# performance as much as possible.

In this chapter, we’re going to cover the following main topics:

  • Why Performance Matters
  • Establishing Baselines
  • Applying Performance Best Practices

By the end of this chapter, you...

Technical requirements

When creating baselines and testing performance for your web application, there is a need for an IDE or editor you feel comfortable with for writing code. We recommend using your favorite editor to view the GitHub repository. Our recommendations include the following:

  • Visual Studio (preferably the latest version)
  • Visual Studio Code
  • JetBrains Rider

The code for this chapter is located in Packt Publishing’s GitHub repository, located at https://github.com/PacktPublishing/ASP.NET-Core-8-Best-Practices.

Why Performance Matters

Performance takes many shapes and forms in web development since there are so many moving pieces to make a website always ready and available to our users. As a developer, if someone asked for help regarding a website being slow, what advice would you recommend? It’s a tough question to answer verbally without examining the website. With websites, there may be times when performance isn’t just one technology; the problem may be more than one bottleneck.

For instance, when loading a web page in the browser, do you see content appear, but images take a long time and paint row by row? How about accessing the database? Do you have slow queries where the server takes a minute to retrieve records? Are web APIs performing at more than two seconds for each request?

As you can see, performance is an analysis of an entire website including browser, server, C#, API, and database.

Amazon published a study calculating that if a page load slowed down...

Establishing Baselines

So, how do you know you’re experiencing a slowdown on a website? Is it because of a recent release of a software product, or a new NuGet package installed causing the slowdown?

While identifying an issue, you may be asking yourself, “what changed?” But the question everyone should be asking is “how do you measure performance?” In order to measure it, there needs to be a baseline of what’s expected when it comes to performance.

Each part of your application should include performance tests. Whether it’s the frontend, a C# subsystem, a web API, or the database, the proper systems should be in place to notify the team when a system isn’t performing as expected.

Using Client-Side Tools

Issues on the client side are mostly due to load times, delivery of resources not found (such as HTML pages, images, CSS, and JavaScript), or JavaScript errors in general. However, this doesn’t mean the entire...

Applying Performance Best Practices

As mentioned at the beginning of this chapter, the content in this chapter applies to client and server techniques to get the most out of your ASP.NET websites.

In this section, we’ll first focus on optimizing the client by applying image optimization, minimizing your requests, using CDNs, and other tips to improve client-side performance. Then we’ll focus on server-side techniques such as optimizing your HTML, caching, and Entity Framework Core performance techniques along with identifying slow queries.

Optimizing client-side performance

In this section, we’ll learn about image optimizations, identifying Google’s Core Web Vitals metrics, using a CDN when applicable, how to minimize requests, and where to place scripts and styles.

Fixing Image Optimization

According to the Web Almanac (https://almanac.httparchive.org/en/2022/media#bytesizes), image optimization is one of the worst problems on the web. The...

Summary

While we covered a lot in this chapter, there are additional ways to achieve performance in web applications using more advanced techniques. The methods covered in this chapter are the best approaches for achieving performance in ASP.NET web applications. More than ever, performance is now considered one of the more important features in web applications, since it’s now usually tied to a company’s finances.

In this chapter, we first learned why performance matters by showing the effects of a slow website, how minor adjustments can produce large dividends, and how search engines reward websites for performance improvements.

We learned how to create baselines to identify possible bottlenecks using performance tools to analyze the client and server-side code with various tools.

Then, we learned about client-side techniques to optimize images, using CDNs to improve the loading of static content, and how to minimize your requests to lower latency issues. We...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
ASP.NET 8 Best Practices
Published in: Dec 2023Publisher: PacktISBN-13: 9781837632121
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jonathan R. Danylko

Jonathan "JD" Danylko is an award-winning, full-stack ASP.NET architect. He's used ASP.NET as his primary way to build websites since 2002 and before that, Classic ASP. Jonathan contributes to his blog (DanylkoWeb) on a weekly basis, has built a custom CMS, is a founder of Tuxboard (an open-source ASP.NET dashboard library), has been on various podcasts, and guest posted on the C# Advent Calendar for 6 years. Jonathan has worked in various industries for small, medium, and Fortune 100 companies, but currently works as an Architect at Insight Enterprise. The best way to contact Jonathan is through GitHub, LinkedIn, Twitter, email, or through the website.
Read more about Jonathan R. Danylko