« Compile Modules into Apache Statically . . . Yes or No | Main | Bulk jpegtran Update Script (with an XML check) »

September 25, 2003

IE Freezes Up Downloading Images

Turns out it's actually a Photoshop 7 problem . . . putting extra junk into jpg images. Read on for the whole story . . .

A few weeks back I worked on a problem with slowness on a site. One of the complaints was along these lines (from a user's email):

When I get to the site I only get the thumbnail pictures for the first ten items, but today also got the thumbnail for the twelve item. The browser then stops downloading with 28 items remaining.

I can select any of the items from the site, except that the picture does not download.

I could not duplicate the behavior no matter how many images I requested. I used ab to generate a load of 10,000 image requests over the course of ~60 seconds and served them all up without issue. Quite puzzling.

I thought maybe these users were on dialup so I got on the modem and did some more testing. It was slow, but the browser was able to get all the images.

It was then that I realized every machine I had fiddled with this was either a Mac or Linux so I fired up VNC to a Windows box at the office and discovered in IE 5.5 I could duplicate the behavior. Seems that on the first request of the page a handful of the images load up. After that no further images can be loaded until the browser is closed and reopened.

I put together a test page in HTML with 545 different image requests. The page loads all but 94 of the images (having loaded 451 images). Started with 20 Apache processes starting up, and bumped it up to 30. Turned off KeepAlive, turned up KeepAliveTimeOut, same results.

Some poking around the internet gets some interesting comments about images in IE, but it wasn't until I got down to the 19th item in the Google search that I found the answer.

Apparently there is a problem with jpeg images created by Photoshop 7. Photoshop embeds an XML preview into the jpeg, which causes IE to choke. I tracked down one of these images, and the xml (239 lines). The xml seems to be Apple's print formatting. It appears that even though these images were created with Photoshop and then resized with convert (of ImageMagick), the xml isn't cleaned out with convert.

1688 images (out of 3793) on the site have this XML. A simple command will get rid of it:
jpegtran -copy none <image> > <new image>

The none option makes sure no extra markers are copied from the source file. Cleaning up this image reduced the size from 21764 to 898 bytes.

Will have to be more careful using Photoshop 7, seems that the "save for web" option doesn't save the extra formatting in the image.

Posted by mike at September 25, 2003 8:27 PM