/    Sign up×
Community /Pin to ProfileBookmark

Safari/javascript image loading problem

Hi,

I’m creating a Google Maps-style large image viewer in Javascript. It currently works in all browsers except for Safari, in which many of the image tiles don’t load. The code I’m using to fetch each image is as follows:

[CODE]/**
* Creates an <img> element, sets its src according to the arguments given
* and sets its absolute position.
*/
function getTile(tileY,tileX)
{
if (tileX >= 0 && tileX < iwt && tileY >=0 && tileY < iht) // Sanity check
{
var tileId = ‘x’ + tileX + ‘y’ + tileY;
var tile = document.createElement(‘img’);
tile.setAttribute(‘id’,tileId);

tile.style.top = (tileY * th) + ‘px’; // ‘th’ is the tile height
tile.style.left = (tileX * tw) + ‘px’; // ‘tw’ is the tile width
var tileSrc = [the appropriate, correct, location of the image tile];
tile.src = tileSrc;
var tileFrame = document.getElementById(’tileframe’);
tileFrame.appendChild(tile);
}
}[/CODE]

This is then called from a for() loop to populate the tile frame. In Safari, however, random tiles do not appear. When the loading is slowed down using a setTimeout(), it’s every second tile that fails to load, in a regular pattern. When I ctrl-click on the blue question mark where the missing images should be and open them in a new window, they usually load fine, or sometimes a ‘connection reset by peer’ error message is displayed, or sometimes Safari tries to save a file with the image data and its HTTP headers… weird.

I’ve checked the packets going back and forth using Ethereal and they appear to be being sent and received OK, so I’m guessing it’s probably a bug in Safari.

Does anyone know how to get around this? I’d be very grateful for any hints.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@themartyAug 31.2006 — my guess is that the pointer to the image gets replaced by a new one before the complete images is loaded in the browser. It shouldn't happen because you're working with local variables inside the function .. but well, since only safari is giving you problems.

what you could try to do is preload the images first, or put them in an array. maybe it helps
Copy linkTweet thisAlerts:
@tomskiauthorAug 31.2006 — No luck, I'm afraid. Preloading and putting the images in an array doesn't have any effect.

Thanks anyway.
Copy linkTweet thisAlerts:
@themartyAug 31.2006 — what happens when you open the webpage (including the images) on your local hard-disk?
Copy linkTweet thisAlerts:
@tomskiauthorSep 01.2006 — This works fine. I've also tried loading static images from the server, which also works fine.

Something I forgot to mention is that the images are being generated dynamically by a fastcgi image server (images are stored as tiled TIFFs, image server converts individual tiles to JPEG on-the-fly), so perhaps this is causing the problem.

Perhaps the issue is a timeout setting that is set too low in the Safari browser, so that the image server doesn't have enough time to create the images?
Copy linkTweet thisAlerts:
@themartySep 01.2006 — Perhaps the issue is a timeout setting that is set too low in the Safari browser, so that the image server doesn't have enough time to create the images?[/quote]

if that is the case, maybe you could try to alter the output-settings of the fastcgi image server? some kind of setting that would force at least the headers of the image to be send right away when it's requested.

in php for example, you can force output to the browser with [b]flush()[/b]
×

Success!

Help @tomski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...