delayed loading of images possible in javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stan k.

    #1

    delayed loading of images possible in javascript?

    First of all let me clarify - I am not talking about having a bunch of
    images loaded all at once (or preloaded) and then controlling the
    display of the images after that point -- I know that can be done. I
    am talking about controlling the loading of those images themselves.

    I was told that the only way to do this was to dynamically write the
    html code via javascript and put time delays inbetween the dynamic
    creation of that html
    such as:

    -
    function DelayedWrite(){
    window.setTimeo ut('DelayedWrit e()',3000);
    document.write( "<img src="http://remoteurl/verybigimage1.j pg");
    window.setTimeo ut('DelayedWrit e()',3000);
    document.write( "<img src="http://remoteurl/verybigimage2.j pg");
    // etc . . .
    }

    onload = window.setTimeo ut('DelayedWrit e()',3000);
    -

    What is occuring is that the initial time delay onload works but the
    delays
    within the function itself do not seem to do anything...

    Anyone have any ideas about how this can be done? perhaps a totally
    different approach even?

    The reason why I need to do this is I am pulling some pretty big
    images of weather maps from another site and presumably when I attempt
    to load several of the maps at once, the remote server thinks it's a
    Denial Of Service (dos) attack and ends up blocking the loading of any
    more images.
  • mesal

    #2
    Re: delayed loading of images possible in javascript?

    stanleykagan@ye pmail.net (stan k.) wrote in message news:<eda56d76. 0402031836.3c77 37e0@posting.go ogle.com>...[color=blue]
    > First of all let me clarify - I am not talking about having a bunch of
    > images loaded all at once (or preloaded) and then controlling the
    > display of the images after that point -- I know that can be done. I
    > am talking about controlling the loading of those images themselves.
    >
    > I was told that the only way to do this was to dynamically write the
    > html code via javascript and put time delays inbetween the dynamic
    > creation of that html
    > such as:
    >
    > -
    > function DelayedWrite(){
    > window.setTimeo ut('DelayedWrit e()',3000);
    > document.write( "<img src="http://remoteurl/verybigimage1.j pg");
    > window.setTimeo ut('DelayedWrit e()',3000);
    > document.write( "<img src="http://remoteurl/verybigimage2.j pg");
    > // etc . . .
    > }
    >
    > onload = window.setTimeo ut('DelayedWrit e()',3000);
    > -
    >
    > What is occuring is that the initial time delay onload works but the
    > delays
    > within the function itself do not seem to do anything...
    >
    > Anyone have any ideas about how this can be done? perhaps a totally
    > different approach even?
    >
    > The reason why I need to do this is I am pulling some pretty big
    > images of weather maps from another site and presumably when I attempt
    > to load several of the maps at once, the remote server thinks it's a
    > Denial Of Service (dos) attack and ends up blocking the loading of any
    > more images.[/color]

    Hi,

    try this code:

    var pics = new Array('verybigi mage1.jpg','ver ybigimage2.jpg' ,...);
    var picNum = 0;
    function DelayedWrite(pi cNum)
    {
    document.write( "<img src='http://remoteurl/verybigimage" + picNum + ".jpg'");
    picNum++;
    if (picNum == maxPictures)
    window.clearInt erval(intName);
    }

    intName = window.setInter val('DelayedWri te()',3000);

    didn't try it but I think it should work..
    good luck

    mesal

    Comment

    • grp_pst_363@yahoo.co.uk

      #3
      Re: delayed loading of images possible in javascript?

      stanleykagan@ye pmail.net (stan k.) wrote in message news:<eda56d76. 0402031836.3c77 37e0@posting.go ogle.com>...[color=blue]
      > -
      > function DelayedWrite(){
      > window.setTimeo ut('DelayedWrit e()',3000);
      > document.write( "<img src="http://remoteurl/verybigimage1.j pg");
      > window.setTimeo ut('DelayedWrit e()',3000);
      > document.write( "<img src="http://remoteurl/verybigimage2.j pg");
      > // etc . . .
      > }
      >
      > onload = window.setTimeo ut('DelayedWrit e()',3000);
      > -
      >
      > What is occuring is that the initial time delay onload works but the
      > delays
      > within the function itself do not seem to do anything...
      >[/color]
      Hi

      The function DelayedWrite() executes 3s after the web page loads.

      [POINT X]
      Once inside the function, all of the of the image tags are written
      with no perceptable delay.
      Each of several timeouts call the function 3s later [GO BACK TO POINT
      X IN INFINITE LOOP].

      It looks like an infinite loop with lots of image tags being written
      every 3 seconds. Maybe this infinite loop clogs up your browser which
      may look like a Denial of Service attack.

      Assuming it doesn't work just putting all the images in with plain
      HTML and the server really does think this is Denial of Service...

      How about having an image of the words "Please Wait" called
      pleaseWait.gif

      In the body for each image you add
      <img name="weather" src="pleaseWait .gif">,

      how about using <body onload="delayLo ad();"> to call the function:

      function delayLoad() {
      var len = document.weathe r.length;
      // multiple objects named "weather" put in DOM as array with length
      var imageURL="";
      for (var i=0; i<len; i++) {
      instr="document .weather["+i+"].src='http://remoteurl/verybigimage"+i +".jpg';";
      window.setTimeo ut(instr,(i+1)* 3000);
      }
      }

      the function assembles strings (instructions) like:
      document.weathe r[0].src='http://remoteurl/verybigimage0.j pg';
      document.weathe r[1].src='http://remoteurl/verybigimage1.j pg';
      document.weathe r[2].src='http://remoteurl/verybigimage2.j pg';
      document.weathe r[3].src='http://remoteurl/verybigimage3.j pg';
      etc

      and sets up timeouts to execute the instructions one by one
      3,6,9,12... seconds after the page loads.

      I've not tested the above code, but I think it would replace the
      "Please Wait" images in sequence with 3s delay between images.

      Hope that's of some use.

      Mark

      Comment

      • @SM

        #4
        Re: delayed loading of images possible in javascript?



        "stan k." a ecrit :[color=blue]
        >
        > First of all let me clarify - I am not talking about having a bunch of
        > images loaded all at once (or preloaded) and then controlling the
        > display of the images after that point -- I know that can be done. I
        > am talking about controlling the loading of those images themselves.
        >
        > I was told that the only way to do this was to dynamically write the
        > html code via javascript and put time delays inbetween the dynamic
        > creation of that html
        > such as:[/color]

        setTimeout('1st _JS_function()' ,2000);
        setTimeout('2nd _JS_function()' ,4000);
        setTimeout('3dr _JS_function()' ,6000);
        setTimeout('4th _JS_function()' ,8000);
        (2 secondes is not enough for me to donwload an heavy image)

        as all setTimeouts are launch together (it is what you do in DelayedWrite)
        you need to increase the delay of each next called

        Take care your DelayedWrite would loop !
        Is there something to stop it ?
        [color=blue]
        > -
        > function DelayedWrite(){
        > window.setTimeo ut('DelayedWrit e()',3000);
        > document.write( "<img src="http://remoteurl/verybigimage1.j pg");
        > window.setTimeo ut('DelayedWrit e()',3000);
        > document.write( "<img src="http://remoteurl/verybigimage2.j pg");
        > // etc . . .
        > }
        >
        > onload = window.setTimeo ut('DelayedWrit e()',3000);
        > -
        >
        > What is occuring is that the initial time delay onload works but the
        > delays
        > within the function itself do not seem to do anything...[/color]

        (3000 = 3000 = 3000 = 3000 is not 3000+3000+3000+ 3000)
        and redo 3 secondes after and again and again
        When does the browser has a little time to draw the page ?


        --
        ******** (enlever/remove [OTER_MOI] du/from reply url) *******
        Stéphane MORIAUX : mailto:stephane OTER_MOImoriaux @wanadoo.fr
        Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

        *************** *************** *************** *************** **

        Comment

        Working...