One byproduct of automated image-slicing software is the plethora of images now populating the Web. As early as 2002 (King 2003) the average web page had over 24 embedded objects, with over half the total page size consisting of images. Today when we analyze web pages we commonly see 50 to 60 images per web page. The more round trip server requests you require in your pages, the longer and more indeterminate your load time becomes. One way to reduce the number of HTTP requests is to combine adjacent images into one composite image and optionally imagemap the links to different areas. This tutorial shows both client and server side techniques you can use to save precious HTTP requests and speed up your site.
One of the steps we go through when speed optimizing a page is to look for adjacent images that can be safely combined. While the file size of the combined image may be slightly larger or smaller than the sum of individual images, the real savings comes from the HTTP requests you save by eliminating objects from your web page. At higher connection speeds especially, the effect of latency and the number of web objects becomes more important than sheer page size on overall display time. The two images below will serve as our simplified example to represent two or more adjacent images ripe to be combine and optionally imagemapped (see Figure 1). Figure 1: A Tale of Two Images Combining these adjacent images creates a slightly larger composite image (805 bytes versus 285+334 = 619 bytes) that saves one HTTP request (see Figure 2). Note that this is a simplified example not designed to show file size savings. We've found that combining JPEGs gives nearly equal or smaller size while combining GIFs can give varied results. The same example using JPEGs yielded a combined image of 1228 bytes, while the 1 jpeg (491 bytes) plus the 2 jpeg (735 bytes) yields 1226 bytes total, nearly the same size at a quality of 25 in Imageready. Note also how much smaller the GIFs are than the JPEGs for these 100 pixel square images showing the importance of choosing the right image format. Figure 2: Combined Image is slightly larger yet saves one HTTP request Whatever format works best for your situation, make sure you use the best graphics optimization techniques from original layered Photoshop files for the best results. If you've got links pointing to each image, you'll need to map these links to your combined image. There are three ways to do this, client-side (works on modern browsers), server-side, and both. First let's look at the old way of doing ISMAPs with a server-side ISMAP: Next what most people use today is a USEMAP or client-side imagemap alone thus: Finally if you want to make the imagemap bulletproof for very old browsers, you can combine these techniques: Combining two or more adjacent images into one composite image can save costly HTTP requests. Each additional HTTP request reduces the predictability of your web page response times because server request times are indeterminate. JPEGs generally combine to similar sizes versus GIFs, which can vary in size due to their compression schemes.Combine Adjacent Images
Two Images = Two HTTP Requests
One Combined Image = One HTTP Request
Server-Side Imagemap: ISMAP
<a href="/cgi-bin/imagemap/combined.map">
<img src="combined.gif" width="210" height="100" alt="combine server-side imagemap"
... style="border-style:none" ismap border="0"></a>
Client-Side Imagemap: USEMAP
<map name="map1"><area href="#1" alt="1" title="1" shape="rect" coords="0,0,100,100">
<area href="#2" alt="2" title="2" shape="rect" coords="100,0,210,100"></map>
<img src="combined.gif" width="210" height="100" alt="combined image client-side imagemap" usemap="#map1" border="0">
Combining Server and Client-Side Imagemaps
<map name="map1"><area href="#1" alt="1" title="1" shape="rect" coords="0,0,100,100">
<area href="#2" alt="2" title="2" shape="rect" coords="100,0,210,100"></map>
<a href="/cgi-bin/imagemap/combined.map">
<img src="combined.gif" width="210" height="100" alt="combine server-client-side imagemap"
... usemap="#map1" style="border-style:none" ismap border=0></a>
Conclusion
Further Reading
By website optimization on 31 May 2006 PM
'emotional developer > detect-Web' 카테고리의 다른 글
CSS를 이용한 효율적인 웹 개발 (0) | 2007.11.18 |
---|---|
웹표준 기반 홈페이지 구축 가이드 (0) | 2007.02.28 |
실전 웹 표준 가이드 by 한국소프트웨어진흥원(2005년) (0) | 2007.02.28 |