Web Performance Best Practices and Rules

Web Performance Best Practices and Rules

Yahoo!’s Exceptional Performance team has identified 34 rules that affect web page performance. YSlow’s web page analysis is based on the 23 of these 34 rules that are testable. Click each performance rule below to see the details.

  1. Minimize HTTP Requests
  2. Use a Content Delivery Network
  3. Avoid empty src or href
  4. Add an Expires or a Cache-Control Header
  5. Gzip Components
  6. Put StyleSheets at the Top
  7. Put Scripts at the Bottom
  8. Avoid CSS Expressions
  9. Make JavaScript and CSS External
  10. Reduce DNS Lookups
  11. Minify JavaScript and CSS
  12. Avoid Redirects
  13. Remove Duplicate Scripts
  14. Configure ETags
  15. Make AJAX Cacheable
  16. Use GET for AJAX Requests
  17. Reduce the Number of DOM Elements
  18. No 404s
  19. Reduce Cookie Size
  20. Use Cookie-Free Domains for Components
  21. Avoid Filters
  22. Do Not Scale Images in HTML
  23. Make favicon.ico Small and Cacheable

Server Response Codes

To make it easy for you to differentiate between the HTTP response codes in the waterfall chart, we’ve color-coded the text and background of each URL.

URL2xxThe server responded with a successful code

URL3xxThe request was redirected to another target

URL4xxA client error occured, for example 404 page not found

URL5xxA server error occured, for example 500 internal server error

URLErrorConnection error, no response from the server

Content that conforms to the HTML 4.0 standard will load faster and work in every browser because the browser then knows what to expect. Note that Microsoft-based tools create content that does not even use the standard ASCII character set, but instead uses many proprietary Microsoft characters that will display in Netscape as question marks and can slow down rendering.

JavaScript is a major source of incompatibility, browser hangs, and pop-up advertising. Style sheets require separate downloads before the page can be displayed. There are some nice features to both JavaScript and style sheets, but at a big cost. Life is better without them.

If left on, reverse DNS will log a client’s machine name rather than IP address, but at a large performance cost. It is better left off. You can always run log analysis tools which look up the names later.

I’ve provided a free analysis tool at my Web site that can tell you whether or not your bottleneck is in DNS, or because of connection time or content size, or is on the server side. Work on improving the slowest part first.

Use simple servlets, CGI, or your Web server’s API rather than any distributed object schemes like CORBA or EJB. Distributed object schemes are intended to improve a programmer’s code-writing productivity, but they do so at an unacceptable cost in performance for end-users.

Your Web server, middleware, and database all will probably do better with more memory, if they still use their hard disks frequently. Hard disks are literally about a million times slower than memory, so you should buy more memory until the disks are phased out.

Spectacular improvements are possible if you are inadvertently doing full-table scans on every hit of a particular URL. Indexes allow you to go directly to the data you need.

If you can cache content in your middleware or servlets, do it. Making connections to a database and using those database connections is typically a bottleneck for performance.

There are many network snooping and monitoring tools to help you do this. Intermittent slowness is often due to packets being lost or corrupted. This is because a time-out period needs to pass before the packet is retransmitted.

  1. Check for standards compliance by using Weblint or other HTML checking tools.
  2. Minimize the use of JavaScript and style sheets.
  3. Turn off reverse DNS lookups in the Web server.
  4. Try out a free analysis tool.
  5. Use simple servlets or CGI.
  6. Get more memory.
  7. Index your database tables well.
  8. Make fewer database queries.
  9. Look for packet loss and retransmission.
  10. Set up monitoring and automated graphing of your Web site’s performance.