[jQuery] image preloading

2006-09-28 Thread Aljosa Mohorovic
is there a preferred way to preload images when site uses jquery? how do you usually preload images? Aljosa Mohorovic ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/

Re: [jQuery] image preloading

2007-02-05 Thread PragueExpat
Using the method below to preload images, I have a simple question: The same variable (in this case 'img') is being used for all preloaded images. Img.src is used to tell the browser to make a call to the server to fetch the image What if the connection to the server is slow (or the image is lar

Re: [jQuery] image preloading

2007-02-05 Thread Luke Lutman
Here's what I use: $(window).bind('load', function(){ var preload = [ '/images/assets/file/1.gif', '/images/assets/file/2.gif', '/images/assets/file/3.gif' ]; $(document.createElement('img')).bind('load', function(){ if(preload[0]) this.src = preload.shift();

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
making all the requests and at the top mimics the normal image load ... the only case where sequencing might help is when the server is configured strangely , or just can't handle the requests... (as in thousands of large graphics??). But I do like the technique! Does that actually load , wait an

Re: [jQuery] image preloading

2007-02-05 Thread Luke Lutman
Ⓙⓐⓚⓔ wrote: > making all the requests and at the top mimics the normal image load ... > the only case where sequencing might help is when the server is > configured strangely , or just can't handle the requests... (as in > thousands of large graphics??). The page I wrote that snippet for was a

Re: [jQuery] image preloading

2007-02-05 Thread Klaus Hartl
Luke Lutman schrieb: > Ⓙⓐⓚⓔ wrote: > > making all the requests and at the top mimics the normal image load ... > > the only case where sequencing might help is when the server is > > configured strangely , or just can't handle the requests... (as in > > thousands of large graphics??). > > The

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
Luke , I don't think that's true... although it's really hard to tell. I know I can do lots of ajaxing at the same time! I wonder if ajaxing the images would keep them in the cache for later use?? On 2/5/07, Klaus Hartl <[EMAIL PROTECTED]> wrote: Luke Lutman schrieb: > Ⓙⓐⓚⓔ wrote: > > making

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
large images vs tiny mouseover images sure makes a difference! I guess we could use your method for all... but I like the idea of getting my little mouseover/active images quickly. I love the brevity of your solution!! $(document.createElement('img')).bind('load', function(){ if(preload[0]) t

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
so the load handler is very special... I didn't know about it! just loading anything calls the load hander! brilliant! On 2/5/07, Luke Lutman <[EMAIL PROTECTED]> wrote: Ⓙⓐⓚⓔ wrote: > I love the brevity of your solution!! > $(document.createElement('img')).bind('load', function(){ >if(prel

Re: [jQuery] image preloading

2007-02-05 Thread Luke Lutman
Ⓙⓐⓚⓔ wrote: > I love the brevity of your solution!! > $(document.createElement('img')).bind('load', function(){ >if(preload[0]) this.src = preload.shift(); > }).trigger('load'); Thanks ;-) It works because the onload handler gets reused -- it fires after the image finishes loading, which

Re: [jQuery] image preloading

2007-02-05 Thread Klaus Hartl
Ⓙⓐⓚⓔ schrieb: > Luke , I don't think that's true... although it's really hard to tell. I > know I can do lots of ajaxing at the same time! I wonder if ajaxing the > images would keep them in the cache for later use?? Well, you do not necessarily have to believe me, but it's even part of the HTT

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
I stand corrected! I've seen multiple ajax requests perhaps they were getting done 2 at a time! good to know! On 2/5/07, Klaus Hartl <[EMAIL PROTECTED]> wrote: Ⓙⓐⓚⓔ schrieb: > Luke , I don't think that's true... although it's really hard to tell. I > know I can do lots of ajaxing at the sam

Re: [jQuery] image preloading

2007-02-05 Thread Ⓙⓐⓚⓔ
I checked my firefox about:config for the connections I had goosed mine up to 8. On 2/5/07, Ⓙⓐⓚⓔ <[EMAIL PROTECTED]> wrote: I stand corrected! I've seen multiple ajax requests perhaps they were getting done 2 at a time! good to know! On 2/5/07, Klaus Hartl < [EMAIL PROTECTED]> wrote:

Re: [jQuery] image preloading

2007-02-06 Thread PragueExpat
Luke, this is a great technique - thanks! As far as my original question, I am still curious to find out the following: With the following preload function: $.preloadImages = function() { for(var i = 0; i > Here's what I use: > > $(window).bind('load', function(){ >var preload =

Re: [jQuery] image preloading

2007-02-06 Thread Luke Lutman
Ok, did a quick test in FF and Safari :-) - The function doesn't wait, it makes all the requests at once (more or less). - The variable gets overwritten. - It doesn't interrupt the download. One thing I did find was that if I do: var img = new Image(); img.onload = function(){ var that = th

Re: [jQuery] image preloading

2007-02-06 Thread PragueExpat
Thanks for testing this. I guess that means that although the variable gets overwritten, the image object remains in memory and the browser's http connection (that is pulling down the current image) remains active until the image is loaded. So basically the image object stays alive, but there is

Re: [jQuery] image preloading

2007-02-06 Thread Nathan Young -X \(natyoung - Artizen at Cisco\)
TECTED] > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of PragueExpat > Sent: Tuesday, February 06, 2007 8:50 AM > To: discuss@jquery.com > Subject: Re: [jQuery] image preloading > > > Thanks for testing this. > > I guess tha

Re: [jQuery] image preloading

2007-02-06 Thread PragueExpat
sts to be dropped. > > --->Nathan > > > > .:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.:||:._.: > ||:. > > Nathan Young > Cisco.com->Interface Development > A: ncy1717 > E: [EMAIL PROTECTED] > >> -Original Message- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of PragueExpat

Re: [jQuery] image preloading

2006-09-28 Thread Sam Collett
Perhaps you could use something like this: $.preloadImages = function() { for(var i = 0; i wrote: > is there a preferred way to preload images when site uses jquery? how > do you usually preload images? > > Aljosa Mohorovic > > ___ > jQuery maili

Re: [jQuery] image preloading

2006-09-28 Thread Dan Atkinson
It would be nice to have this running in the background on a thickbox-esque page, so that, while the user is admiring picture A, picture B is happily loading away in the background. Sam Collett wrote: > > Perhaps you could use something like this: > > $.preloadImages = function() > { > f

Re: [jQuery] image preloading

2006-09-28 Thread Klaus Hartl
Sam Collett schrieb: > Perhaps you could use something like this: > > $.preloadImages = function() > { > for(var i = 0; i { > img = new Image(); > img.src = arguments[i]; > } > } > > Then you call it as soon as possible (it doesn't have to be in > $

Re: [jQuery] image preloading

2006-09-28 Thread Ⓙⓐⓚⓔ
you get more mileage from the tcp/ip connection when you make all requests at the same time. On 9/28/06, Dan Atkinson <[EMAIL PROTECTED]> wrote: > > It would be nice to have this running in the background on a thickbox-esque > page, so that, while the user is admiring picture A, picture B is happi