Posted on May 21, 2009 - by ruby
Website Optimization Best Practices, speed up your website load
Once i have performance issue in a website project i am working at, and i have wasted hours of my time to fix it up both in the server-side and client-side, for future checklist i searched on web and found great list of best practices to speed up our web page load at yahoo developer network.
Below are the summary:
- Minimize HTTP Requests, this can be done with the following practices:
- Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script
- CSS Sprites, combined your background image into a single image and use CSS property to control the position of image segment
- Image maps combine multiple images into a single image
- Inline images use the data: URL scheme to embed the image data in the actual page
- Use a Content Delivery Network
- Add an Expires or a Cache-Control Header:
- For static components: implement “Never expire” policy by setting far future Expires header
- For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests
- Compress HTTP text response with Gzip Components (text, html, json, xml)
- Put CSS/stylesheets declarations at the Top
- Put client side scripts at the bottom, some scripts can be placed at the bottom but some may not, so use it as neccessary
- Avoid CSS Expressions, since it is evaluated more than we expect: on load, resize, scrolled, and even on mousemove
- Make JavaScript and CSS External, take the benefit of browser caching mechanism
- Reduce DNS Lookups in server’s settings
- Minify JavaScript and CSS, you can use JSMin and YUI Compressor to achieve this goal
- Avoid Redirects, one of the common mistaken is missing a trailing slash (/) from a URL, i.e: http://www.domain.tld/directory will be 301 redirected to http://www.domain.tld/directory/
- Avoid scripts duplication
- Configure ETags, Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser’s cache matches the one on the origin server.
- Make Ajax Response Cacheable, some rules should apply also to ajax are: Add an Expires or a Cache-Control Header, Compress HTTP reponse with Gzip component, Reduce DNS Lookups, Minify JavaScript, Avoid Redirects, Configure ETags
- Flush the Response Buffer Early, in php there is flush(), and response.flush in asp
- Use GET for AJAX Requests, because POST method is implemented in the browsers as a two-step process: sending the headers first, then sending data.
- Post-load Components, Load page element only when it is neccessary or after the top priority elements is loaded. Have a l ook at YUI Image Loader, YUI Get Utility, or jQuery Lazy Load
- Preload Components
- Unconditional preload – as soon as onload fires, you go ahead and fetch some extra components.
- Conditional preload – based on a user action you make an educated guess where the user is headed next and preload accordingly.
- Anticipated preload – preload in advance before launching a redesign.
- Reduce the Number of DOM Elements, means you need to optimize your markup, do not use new element if you can solve the issue in different ways
- Split Components Across Domains, Splitting components allows you to maximize parallel downloads.
- Avoid using iframes (and frames either)
- No 404s, because the HTTP request is expensive
- Reduce Cookie Size, It’s important to keep the size of cookies as low as possible to minimize the impact on the user’s response time
- Use Cookie-free Domains for Components, You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.
- Minimize DOM Access:
- Cache references to accessed elements
- Update nodes “offline” and then add them to the tree
- Avoid fixing layout with JavaScript
- Develop Smart Event Handlers, attach event handler via parent elemnt wherever possible
- Choose
over @import for stylesheets - Avoid Filters, mostly comes when dealing with IE6, YDN recommended using PNG8 which working fine in IE, but for me better shoot the IE6 with a machine gun (a lot headache cos of IE6 already)
- Optimize Images: Try converting GIFs to PNGs, Run pngcrush (or any other PNG optimizer tool) on all your PNGs, Run jpegtran on all your JPEGs
- Optimize CSS Sprites:
- Arranging the images in the sprite horizontally as opposed to vertically
- Combining similar colors in a sprite helps you keep the color count low
- “Be mobile-friendly” and don’t leave big gaps between the images in a sprite.
- Don’t Scale Images in HTML
- Make favicon.ico Small and Cacheable
- Keep Components under 25K
- Pack Components into a Multipart Document
Check out the original article at YDN
This entry was posted on Thursday, May 21st, 2009 at 23:28 and is filed under Ajax XMLHttpRequest, Featured. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Visit My Website
June 1, 2009
Permalink
[...] Link: http://www.chazzuka.com: Website Optimization Best Practices, speed up your website load [...]
Visit My Website
June 11, 2009
Permalink
Excellent tips….I’ve heard of some of them, but you have a lot of them! Thanks!
Visit My Website
June 13, 2009
Permalink
these information are the same if you install yslow from yahoo in firefox.
Visit My Website
June 24, 2009
Permalink
great list..
just adding, reduce grabbing images from outbound url,
that one can also minimize HTTP requests
Visit My Website
August 21, 2009
Permalink
I just browsed through the original post it was too long, yours is nice and cut short. also thanks for giving the original post link.
Was quite useful.
Also you or yahoo have not mentioned about the flash header…
Austin
Visit My Website
February 27, 2010
Permalink
Pretty good summary. Big fan of sprites – which is an art in itself for I’ve seen pretty bad and inefficient ones out there. But not always possible when catering for dynamic user content.