Wednesday, March 25, 2009

Minimize HTTP Requests by CSS Sprites


Problem:



The new launched Stuff.co.nz is facing a loading speed issue. Currently has around 190 HTTP requests on pages, 126 image http requests on homepage, 78 CSS background images.I've done some research on optimization, 80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.


How to improve?


According to first rule of 14 Rules for Faster-Loading Web Sites, Minimize HTTP Requests
http://stevesouders.com/examples/rules.php
http://developer.yahoo.com/performance/rules.html#num_http


How to optimize?


CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.
CSS Sprites Generator http://www.csssprites.com/


Example


Little icons on one image file Examples:
Google http://www.google.com/images/nav_logo3.png

Yahoo! http://l.yimg.com/a/i/ww/sp/trough_2.0_062308.gif

Delicious http://static.delicious.com/img/del_sprite_smallIcons.gif

0 comments:

Post a Comment