magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1999 > 04 > Programming with Perl

Patch Up Those Image Tags

Well, last month's column was a pretty heavy piece of work, clocking in at 312 lines of code, and a correspondingly large amount of descriptive text. This month, I decided to get back to basics and tackle a simple but annoying problem of your typical Web page: making it load faster.

One of the things you can do to make a Web page appear to load faster is to give the browser hints about the ultimate dimensions (width and height) of its images. In modern HTML, the IMG tag accepts width and height attributes that give the pixel dimensions of the image. The browser can use this to leave a hole of the appropriate size while the rest of the HTML is still loading, and even while the image data is being fetched in a separate HTTP transaction. While this doesn't actually make the page load any faster, it seems to reassure users a bit more, since things aren't jumping around for as long.

But to make this work, you've got to insert the actual dimensions into the HTML code. Doing this by hand means downloading the image into your favorite image manipulation tool, checking the information for the picture, noting the dimensions, and then invoking your favorite text editor to hack the HTML. Bleh. No wonder it doesn't get done as often as it should.

However, thanks to the nice Image::Size module (available from the CPAN at www.cpan.org/CPAN.html and other places), I was able to write a program to automatically fetch the image, compute its dimensions, and then edit that data right into the HTML.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2