This book is designed to allow you, as a developer, to get the best performance out of your websites. This book delivers details, best practices, caveats, tips, and tricks to improve the performance of your websites and reduce the load times of your web pages.
Every new chapter in this book is intended to teach the reader a new web performance concept. As you follow along with each chapter, and open the accompanying source code, you will be able to follow the steps provided to improve the performance of the sample website. Each chapter in the book is also designed to work as a standalone concept; that is, you can chose a chapter and apply just that technique and you will improve your website. As we progress through the chapters, we will be constantly improving the sample website and each technique will take the sample website closer to performance nirvana.
This book is for web developers who are looking to improve the performance of their web pages. It is also for developers who are looking to dive a little deeper into web development and understand the page lifecycle that is happening as a user loads their website. This book covers fundamental techniques that are applicable to web pages regardless of the programming language. The techniques that are covered are generally universal, but aimed toward the ASP.NET website developer.
Part 1 “Defining performance” teaches you the valuable skills you need to understand in order to begin improving the performance of your website. It explains the importance of focusing on the front-end code in order to achieve the biggest and most scalable gains.
Chapter 1 explains the value and benefits that optimizing your websites will bring. It also shows you the steps you’ll need to take in order to optimize your websites by using the Performance Cycle.
Chapter 2 focuses on the basics of HTTP so you understand the processes that take place under the hood. The chapter then shows you the essential tips and tools you’ll need in order to interpret performance charts when you’re profiling your website. You’ll then look at the different profiling tools that you’ll be using throughout this book.
Part 2 “General performance best practices” is where the real work begins. You’ll start to investigate and apply individual techniques to improve the performance of your web applications.
Chapter 3 covers compression and why you should use it. After going through the different types of compression, you’ll look at the Surf Store application used throughout this book. You’ll then apply compression to the sample application and compare the difference in page sizes.
Chapter 4 looks at HTTP caching and shows how you can use it to improve the performance of your web applications. The chapter also shows you how to apply output caching to your ASP.NET projects.
Chapter 5 explains the new bundling and minifying features built into ASP.NET 4.5. You’ll then run through examples and apply them to the Surf Store application.
Chapter 6 dives a little deeper into web performance and offers HTML optimization tips and techniques you can apply to your web pages. It also explains the performance benefits HTML5 can bring, as well as ways to integrate these HTML5 techniques into your web pages.
Chapter 7 discusses the importance of image optimization and how it can significantly reduce the weight of your web pages. This chapter looks at the different image optimization tools available and shows you how to use them. The chapter discusses the benefits data URIs can bring and walks you through an end-to-end example that demonstrates how you can apply data URIs to an ASP.NET application.
Chapter 8 discusses ETags and explains their usage on the web today. It explores whether you should or shouldn’t be using them in your web application and runs through an example that demonstrates how to remove ETags from your application.
Chapter 9 focuses on Content Delivery Networks (CDNs) and the benefits they can bring in terms of speed and performance. It teaches you how to build a simple HTML helper that you can use in your ASP.NET development when dealing with CDNs. This technique can help you save money and bandwidth expenses when dealing with CDNs in a development environment.
Part 3 “ASP.NET-specific techniques” starts to shift focus slightly and looks at ASP.NET optimization techniques that are based on server-side code.
Chapter 10 teaches you how to tweak your ASP.NET MVC applications to squeeze precious milliseconds out of your page load time. The chapter shows you how to apply a profiler called MiniProfiler to your MVC application and use it to pinpoint bottlenecks in your application.
Chapter 11 shows simple techniques you can use to improve the performance of your ASP.NET Web Forms applications, how to apply MiniProfiler to your ASP.NET Web Forms application, and how to identify any bottlenecks in your code.
Chapter 12, the final chapter, discusses the importance of server-side data caching. It teaches you how to apply the features built into the System.Runtime.Caching namespace and illustrates an end-to-end example, showing data caching in action. The chapter reviews the progress you’ve made and compares the Surf Store application before and after we made improvements. The speed differences between the applications are astonishing!
All source code in the book is in a fixed-width font, which sets if off from the surrounding text. In many listings, the code is annotated to point out the key concepts. We have tried to format the code so that it fits within the available space in the book by adding line breaks and using indentation carefully. Sometimes, however, very long lines include line-continuation markers. Code examples appear throughout this book. Long listings appear under clear listing headers; shorter listings appear between lines of text or in an illustration.
Throughout this book, I make use of C#, JavaScript, CSS, and HTML as much as possible. I am a fan of both ASP.NET Web Forms and ASP.NET MVC, and each chapter includes sample code for both frameworks. This allows you to choose either framework and still learn and apply the same techniques.
All of the sample code is available for download on the Github website at https://github.com/deanhume/FastASPNetWebsites as well as from the publisher’s website at www.manning.com/FastASP.NETWebsites. Each chapter has its own source code that you should be able to fire up and begin working on immediately. There is no setup involved.
In order to run the code samples that are provided in this book, you will need a copy of Visual Studio 2012. You can use either Visual Studio Express 2012, which is a free download on the Microsoft website, or the full version of Visual Studio 2012. The source code will only work with versions of Visual Studio 2012 and not previous versions as there are some newer features in Visual Studio 2012 that have been built to improve the performance of web pages.
You will also need a copy of either the Yahoo! YSlow tool or the Google PageSpeed tool to profile the sample web pages in this book. These two tools are both free and work with most modern browsers. You will need to check with the vendors to find out which browsers they are compatible with.
The purchase of Fast ASP.NET Websites includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and other users. To access the forum and subscribe to it, visit www.manning.com/FastASP.NETWebsites. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). Let your voice be heard, and keep the author on his toes!
The figure on the cover of Fast ASP.NET Websites is captioned “African Warrior.” The illustration is taken from a Spanish compendium of regional dress customs first published in Madrid in 1799. The book’s title page states:
Coleccion general de los Trages que usan actualmente todas las Nacionas del Mundo desubierto, dibujados y grabados con la mayor exactitud por R.M.V.A.R. Obra muy util y en special para los que tienen la del viajero universal.
Which we translate, as literally as possible, thus:
General collection of costumes currently used in the nations of the known world, designed and printed with great exactitude by R.M.V.A.R. This work is very useful especially for those who hold themselves to be universal travelers.
Although nothing is known of the designers, engravers, and workers who colored this illustration by hand, the “exactitude” of their execution is evident in this drawing. The “African Warrior” is just one of many figures in this colorful collection. Their diversity speaks vividly of the uniqueness and individuality of costumes from different countries around the world just 200 years ago.
We at Manning celebrate the inventiveness, the initiative, and the fun of the computer business with book covers based on the rich diversity of life of two centuries ago brought back to life by the pictures from this collection.
18.117.119.7