/    Sign up×
Community /Pin to ProfileBookmark

Preloading images whose URLs are redirected by the server

I’m working on a bread-and-butter image rotator. You can see the general idea at the top of legionofvalor.guildportal.com – don’t look at the current code there; it’s not relevant.

I have a JS Image object outside the DOM whose src attribute I set to the URL of the next image. When the onload event fires, I change the src attribute of the visible image and execute the transition. So far, all very standard. But in this situation, it doesn’t actually work.

[B]The background[/B]

The images in question are stored at pbase.com. Their “durable” links are of the form [url]http://www.pbase.com/image/51387767.jpg[/url]. However, these durable links all result in redirects to another server. For example, if you enter the previous link in your browser, you might actually end up with [url]http://cakeru.image.pbase.com/image/51387767.jpg[/url]. Every redirect is different. Of course, the actual number of servers is finite, but the number in rotation for a particular image is not predictable.

[B]The problem[/B]

This redirecting breaks the standard image preloading scheme. The browser accepts the redirect, downloads the image data, and caches it under the actual (redirected) URL, not the canonical URL originally assigned to the Image object. If another Image’s src property is then set to the canonical URL, the browser will re-download the image from another server.

[B]What I think I need[/B]

Some way to ask an Image “What URL did your data come from, really?” Unfortunately, the src attribute is not updated. And actually, I have enumerated every attribute of the Image in question, and nothing looks at all promising. If I could find the server-specific URL, it would be fine to assign that same URL to the displayed image, and the data would then come from the cache.

[B]What I might really need[/B]

Any way of preloading images that accomodates the case in which the server does redirection on the image URLs. Or alternatively, some way of identifying the target of a redirected URL from within JavaScript.

I’ve spent hours looking for comments on this type of problem and have come up with absolutely nothing. I’m not sure if I’m using the wrong names for things or whether this is truly an uncommon problem. In any case, I’d appreciate any help or pointers.

Thanks,
Garth

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @GarthSnyder 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.17,
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,
)...