Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Trying to use preloaded images in img src

    I'm loading a bunch of html into a span, and from there, in the onload, I'm using JS to reformat the html and repopulate the span's innerhtml. The issue I'm having is with the images. I can set the img src to the image on the server, but it loads each image over and over again, and they are the same image. I've tried using some JS for preloading the image, but again, that doesn't seem to work. It thinks the reference to the preloaded image is the source.

    Is there a way to reference the initial source of an image to a preloaded image? The page and html are already loaded. When I'm rewriting the innerHTML with JS, is there a way to set the src of the image so it uses a preloaded image instead of hitting the server over and over again for 100s of times just to get the same image??

    I've been beating my head on this for quite awhile and not getting anywhere. Any help or ideas are greatly appreciated. Thank you.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    it should cache the pic the first time, so the image data is not retransmitted. if you don't care about IE6 and IE7 support, you can read the image into a dataurl and store it as a string. you tehn set the source to that string, and the image displays. heck, you can even use globalStorage to save that string to the user's hard drive to guarantee that your server is not bother again.

    Both concepts are coming to IE8, and already present in the other guys.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •