How to cache images in VBScript?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: How to cache images in VBScript?

  1. #1
    Larry Serflaten Guest

    How to cache images in VBScript?

    I've looked high and low for a method to force images to be cached.

    I have images displayed on an HTML page that I want to cycle other
    images into.

    (Using IE 5.5) I have already tried these methods

    - Using the EXPIRES meta tag, setting to expire at a later date
    - Using hidden IMG objects, setting the src property
    - Creating a 'global' array of IMG objects, setting their src property
    - Using multiple attributes in the IMG tag:
    <img src="pic.gif" src1="pic1.gif" src2="pic2.gif">
    Then attempting: myimage.src = myimage.src1
    - Defining an image class with a public src property

    In each case, IE will try to download the image again, slowing down
    the response time.

    How is this done, so that IE does not try to download an image on
    each change (click)? I have several places on the page that will
    all use these same images so I can't just place them all on top of
    each other, I have to be able to assign them to the various images
    on the page.


    I am trying to do this with VBScript. My current test page is at:
    http://www.usinternet.com/users/serf...games/test.htm

    Any help is appreciated!

    LFS



  2. #2
    Lior Amar Guest

    Re: How to cache images in VBScript?

    IE doesn't try and redownload the file what it does is a round trip
    verification. Nothing more annoying then when the **** image does not need
    to be changed and it does this round trip. The slow down you're
    experiencing is the following thing...

    Page gets loaded, IE gets SRC info and says is it the same yes, don't
    download --- No than download. The problem with this approach is you should
    expect a 250ms wait for the comparison. So the real question is how do we
    tell IE not to do this verification and the answer I have for you is...I
    don't know. Been looking into it (on and off) for the last 6 days and the
    closest I've come to a solution is trying to figure out how to set the
    source of an image to the cached directory. Problem with that is if user
    clears cache then bye bye site....of course a million and one things we can
    do to solve that problem so the real question is with out using IE APIs can
    we tell it not to do a GET on the server for the image?

    If you do figure it out let me know...



    --
    Lee Amar
    Chief Technology Officer
    www.ostnet.com
    OSTnet OpenSource Technologies Inc
    lior@ostnet.com
    OSTnet develops software and subcontracts much of the work to registered
    developers over the Internet. Members of www.ostnet.com are free to view all
    company projects open for tender (in the Projects section of the Developer
    Home) and can apply to work on these projects. We prequalify all of our
    members to determine their level and areas of expertise. Please feel free to
    sign up at your leisure and write the exams in order to qualify yourself for
    OSTnet projects.



    "Larry Serflaten" <serflaten@usinternet.com> wrote in message
    news:39f7e515@news.devx.com...
    > I've looked high and low for a method to force images to be cached.
    >
    > I have images displayed on an HTML page that I want to cycle other
    > images into.
    >
    > (Using IE 5.5) I have already tried these methods
    >
    > - Using the EXPIRES meta tag, setting to expire at a later date
    > - Using hidden IMG objects, setting the src property
    > - Creating a 'global' array of IMG objects, setting their src property
    > - Using multiple attributes in the IMG tag:
    > <img src="pic.gif" src1="pic1.gif" src2="pic2.gif">
    > Then attempting: myimage.src = myimage.src1
    > - Defining an image class with a public src property
    >
    > In each case, IE will try to download the image again, slowing down
    > the response time.
    >
    > How is this done, so that IE does not try to download an image on
    > each change (click)? I have several places on the page that will
    > all use these same images so I can't just place them all on top of
    > each other, I have to be able to assign them to the various images
    > on the page.
    >
    >
    > I am trying to do this with VBScript. My current test page is at:
    > http://www.usinternet.com/users/serf...games/test.htm
    >
    > Any help is appreciated!
    >
    > LFS
    >
    >




  3. #3
    Avron Polakow Guest

    Re: How to cache images in VBScript?

    In both browsers IE and NS, this is a browser preference setting!!
    The user can override your own programming techniques.
    In IE you set this with: Tools > Internet Options > General > Settings >
    Check "Every Time you start Internet Explorer"

    WORKAROUND
    ~~~~~~~~~~~~~
    An easy workaround is to use an hidden frame with the technique of reading
    the images into an array.
    Then in the target frame create images with NAME attributes and empty
    <SRC>s and
    then copy the images from the hidden frame array of images after the
    target frame as loaded
    (from the onLoad event or by creating a user-defined postevent).

    I don't know if the browsers actually place images placed in arrays in
    their caches or keep them in their intestines.
    Check it out!

    BTW, you can use this technique to choose which images you want to
    download again.

    You will find that IE is VERY SLOW using arrays. Benchmark this technique
    against NS.

    Larry Serflaten wrote:

    > I've looked high and low for a method to force images to be cached.
    >
    > I have images displayed on an HTML page that I want to cycle other
    > images into.
    >
    > (Using IE 5.5) I have already tried these methods
    >
    > - Using the EXPIRES meta tag, setting to expire at a later date
    > - Using hidden IMG objects, setting the src property
    > - Creating a 'global' array of IMG objects, setting their src property
    > - Using multiple attributes in the IMG tag:
    > <img src="pic.gif" src1="pic1.gif" src2="pic2.gif">
    > Then attempting: myimage.src = myimage.src1
    > - Defining an image class with a public src property
    >
    > In each case, IE will try to download the image again, slowing down
    > the response time.
    >
    > How is this done, so that IE does not try to download an image on
    > each change (click)? I have several places on the page that will
    > all use these same images so I can't just place them all on top of
    > each other, I have to be able to assign them to the various images
    > on the page.
    >
    > I am trying to do this with VBScript. My current test page is at:
    > http://www.usinternet.com/users/serf...games/test.htm
    >
    > Any help is appreciated!
    >
    > LFS



  4. #4
    Lior Amar Guest

    Re: How to cache images in VBScript?

    Avron,

    I believe I tried this but you still get that round trip check that both
    browsers do to assure the image size is the same. The problem is how to
    prevent that round trip from happening. Let's look at it from the point of
    view of the browser: ImageA wants to be displayed. No problem let's first
    check our cache for ImageA. Found ImageA, great but has the image been
    updated? Let's check with the server and verify if the image is the same.
    Yes - No do whatever. It's that **** check that is the most annoying thing
    and it slows everything down. You might say a 120ms to 250ms check is
    nothing but when you have 100 images it becomes a long wait.

    As a developer I understand the developers of the browsers thought process
    behind it but they should have left a back door to allow developers to
    control this check.

    If you wanna brainstorm on this let me know...be glad to get another point
    of view on this problem...


    --
    Lee Amar
    Chief Technology Officer
    www.ostnet.com
    OSTnet OpenSource Technologies Inc
    lior@ostnet.com
    OSTnet develops software and subcontracts much of the work to registered
    developers over the Internet. Members of www.ostnet.com are free to view all
    company projects open for tender (in the Projects section of the Developer
    Home) and can apply to work on these projects. We prequalify all of our
    members to determine their level and areas of expertise. Please feel free to
    sign up at your leisure and write the exams in order to qualify yourself for
    OSTnet projects.



    "Avron Polakow" <avronp@inter.net.il> wrote in message
    news:3A02796F.FEDA4823@inter.net.il...
    > In both browsers IE and NS, this is a browser preference setting!!
    > The user can override your own programming techniques.
    > In IE you set this with: Tools > Internet Options > General > Settings >
    > Check "Every Time you start Internet Explorer"
    >
    > WORKAROUND
    > ~~~~~~~~~~~~~
    > An easy workaround is to use an hidden frame with the technique of reading
    > the images into an array.
    > Then in the target frame create images with NAME attributes and empty
    > <SRC>s and
    > then copy the images from the hidden frame array of images after the
    > target frame as loaded
    > (from the onLoad event or by creating a user-defined postevent).
    >
    > I don't know if the browsers actually place images placed in arrays in
    > their caches or keep them in their intestines.
    > Check it out!
    >
    > BTW, you can use this technique to choose which images you want to
    > download again.
    >
    > You will find that IE is VERY SLOW using arrays. Benchmark this technique
    > against NS.
    >
    > Larry Serflaten wrote:
    >
    > > I've looked high and low for a method to force images to be cached.
    > >
    > > I have images displayed on an HTML page that I want to cycle other
    > > images into.
    > >
    > > (Using IE 5.5) I have already tried these methods
    > >
    > > - Using the EXPIRES meta tag, setting to expire at a later date
    > > - Using hidden IMG objects, setting the src property
    > > - Creating a 'global' array of IMG objects, setting their src property
    > > - Using multiple attributes in the IMG tag:
    > > <img src="pic.gif" src1="pic1.gif" src2="pic2.gif">
    > > Then attempting: myimage.src = myimage.src1
    > > - Defining an image class with a public src property
    > >
    > > In each case, IE will try to download the image again, slowing down
    > > the response time.
    > >
    > > How is this done, so that IE does not try to download an image on
    > > each change (click)? I have several places on the page that will
    > > all use these same images so I can't just place them all on top of
    > > each other, I have to be able to assign them to the various images
    > > on the page.
    > >
    > > I am trying to do this with VBScript. My current test page is at:
    > > http://www.usinternet.com/users/serf...games/test.htm
    > >
    > > Any help is appreciated!
    > >
    > > LFS

    >




  5. #5
    Larry Serflaten Guest

    Re: How to cache images in VBScript?

    "Lior Amar" <lior@ostnet.com> wrote in message news:3a02d58c$1@news.devx.com...

    > As a developer I understand the developers of the browsers thought process
    > behind it but they should have left a back door to allow developers to
    > control this check.
    >
    > If you wanna brainstorm on this let me know...be glad to get another point
    > of view on this problem...
    >


    I have found a back door, so to speak, but it is in the response header,
    which, AFAIK is only available to the server...

    http://msdn.microsoft.com/workshop/A...f/perftips.asp
    3/4 of the way down under: Leverage the HTTP Expires Header

    I am currently looking into 'persistance' as it pertains to page elements.

    BTW For some reason I could not U/L to my ISP yesterday, everything
    I sent turned up as a 0 byte file, and I overwrote the test.htm file I posted here
    as a link in my original message. If you need an example of the problem,
    I'll be happy to post one here...

    --
    LFS (serflaten@usinternet.com)
    President - ChildsPlay Software Services





  6. #6
    Larry Serflaten Guest

    Re: How to cache images in VBScript?

    I think I am hot on the trail, here, this my be IE5 specific, but, at least its a start:
    http://msdn.microsoft.com/workshop/a...gerollover.asp

    However, even their own sample works 'intermitantly' sometimes sending a request,
    sometimes not...

    --
    LFS (serflaten@usinternet.com)
    President - ChildsPlay Software Services





  7. #7
    Steve Cochran Guest

    Re: How to cache images in VBScript?

    You could do it this way. Mouseover the bug:





    Well, I forgot they won't let binaries in here.

    here's the code:

    <IMG language=vbs id=img1 onmouseover=switchit() onmouseout=switchback()>
    <IMG id=img2 style="DISPLAY: none" > <IMG id=img3 style="DISPLAY: none" >
    <SCRIPT language=vbs>
    sub window_onload()
    img1.src=img3.src
    end sub
    sub switchit()
    img1.src=img2.src
    end sub
    sub switchback()
    img1.src=img3.src
    end sub
    </SCRIPT>

    You don't need all that xml stuff.

    steve

    "Larry Serflaten" <serflaten@usinternet.com> wrote in message news:3a02edae@news.devx.com...
    > I think I am hot on the trail, here, this my be IE5 specific, but, at least its a start:
    > http://msdn.microsoft.com/workshop/a...gerollover.asp
    >
    > However, even their own sample works 'intermitantly' sometimes sending a request,
    > sometimes not...
    >
    > --
    > LFS (serflaten@usinternet.com)
    > President - ChildsPlay Software Services
    >
    >
    >
    >



  8. #8
    Lior Amar Guest

    Re: How to cache images in VBScript?

    Gonna test it to see if the server is still receiving a Get. In all honesty
    from the looks of this code it will still send a Get to the Browser. I'll
    let you know when I complete my test.


    --
    Lee Amar
    Chief Technology Officer
    www.ostnet.com
    OSTnet OpenSource Technologies Inc
    lior@ostnet.com
    OSTnet develops software and subcontracts much of the work to registered
    developers over the Internet. Members of www.ostnet.com are free to view all
    company projects open for tender (in the Projects section of the Developer
    Home) and can apply to work on these projects. We prequalify all of our
    members to determine their level and areas of expertise. Please feel free to
    sign up at your leisure and write the exams in order to qualify yourself for
    OSTnet projects.


    "Larry Serflaten" <serflaten@usinternet.com> wrote in message
    news:3a02edae@news.devx.com...
    > I think I am hot on the trail, here, this my be IE5 specific, but, at

    least its a start:
    >

    http://msdn.microsoft.com/workshop/a...agerollover/im
    agerollover.asp
    >
    > However, even their own sample works 'intermitantly' sometimes sending a

    request,
    > sometimes not...
    >
    > --
    > LFS (serflaten@usinternet.com)
    > President - ChildsPlay Software Services
    >
    >
    >
    >




  9. #9
    Larry Serflaten Guest

    Re: How to cache images in VBScript?

    Obviously your example wasn't quite ready to run as is, and I am
    not really looking for the rollover effect, I am trying to cycle through
    6 separate images. Adjusting for these changes, I have included your
    example below using 3 images. I find it still sends a request off to the
    server. Also, hiding the images really had no effect, as I tried removing
    the STYLE property (they became visible) and still a request was sent
    to the server on each click.

    Do you see any improvements that would help avoid that request?

    --
    LFS (serflaten@usinternet.com)
    President - ChildsPlay Software Services

    <HTML>
    <HEAD></HEAD>
    <BODY>
    Test image follows:<BR>

    <IMG language=vbs id=imgUser onClick=Click() onDblClick=Click()>
    <IMG id=img0 style="DISPLAY: none" SRC="http://usinternet.com/users/serflaten/games/green.gif">
    <IMG id=img1 style="DISPLAY: none" SRC="http://usinternet.com/users/serflaten/games/yellow.gif">
    <IMG id=img2 style="DISPLAY: none" SRC="http://usinternet.com/users/serflaten/games/red.gif">
    <SCRIPT language=vbs>
    Dim Count

    Sub Window_Onload()
    imgUser.src=img0.src
    End Sub

    Sub Click()
    Count = (Count + 1) Mod 3
    trg = "img" & CStr(Count)
    imgUser.src = document.all(trg).src
    End Sub

    </SCRIPT>

    </BODY>
    </HTML>



  10. #10
    Lior Amar Guest

    Re: How to cache images in VBScript?

    Nice try Steve but still getting Gets to the Server. I believe the only way
    we can avoid the **** round trip is to set the image source to Local. To do
    that we need to either get the user to accept a upload or to get the cache
    directory and take it from their. Is it possible??? Gonna play with it
    some more this weekend, let you know what I find if I find anything.


    --
    Lee Amar
    Chief Technology Officer
    www.ostnet.com
    OSTnet OpenSource Technologies Inc
    lior@ostnet.com
    OSTnet develops software and subcontracts much of the work to registered
    developers over the Internet. Members of www.ostnet.com are free to view all
    company projects open for tender (in the Projects section of the Developer
    Home) and can apply to work on these projects. We prequalify all of our
    members to determine their level and areas of expertise. Please feel free to
    sign up at your leisure and write the exams in order to qualify yourself for
    OSTnet projects.




    "Larry Serflaten" <serflaten@usinternet.com> wrote in message
    news:3a02edae@news.devx.com...
    > I think I am hot on the trail, here, this my be IE5 specific, but, at

    least its a start:
    >

    http://msdn.microsoft.com/workshop/a...agerollover/im
    agerollover.asp
    >
    > However, even their own sample works 'intermitantly' sometimes sending a

    request,
    > sometimes not...
    >
    > --
    > LFS (serflaten@usinternet.com)
    > President - ChildsPlay Software Services
    >
    >
    >
    >




  11. #11
    Steve Cochran Guest

    Re: How to cache images in VBScript?

    Check out his article and the section on cache-control extensions and see if
    that helps:

    http://msdn.microsoft.com/workshop/A...f/perftips.asp

    steve

    "Lior Amar" <lior@ostnet.com> wrote in message
    news:3a0469e4$1@news.devx.com...
    > Nice try Steve but still getting Gets to the Server. I believe the only

    way
    > we can avoid the **** round trip is to set the image source to Local. To

    do
    > that we need to either get the user to accept a upload or to get the cache
    > directory and take it from their. Is it possible??? Gonna play with it
    > some more this weekend, let you know what I find if I find anything.
    >
    >
    > --
    > Lee Amar
    > Chief Technology Officer
    > www.ostnet.com
    > OSTnet OpenSource Technologies Inc
    > lior@ostnet.com
    > OSTnet develops software and subcontracts much of the work to registered
    > developers over the Internet. Members of www.ostnet.com are free to view

    all
    > company projects open for tender (in the Projects section of the Developer
    > Home) and can apply to work on these projects. We prequalify all of our
    > members to determine their level and areas of expertise. Please feel free

    to
    > sign up at your leisure and write the exams in order to qualify yourself

    for
    > OSTnet projects.
    >
    >
    >
    >
    > "Larry Serflaten" <serflaten@usinternet.com> wrote in message
    > news:3a02edae@news.devx.com...
    > > I think I am hot on the trail, here, this my be IE5 specific, but, at

    > least its a start:
    > >

    >

    http://msdn.microsoft.com/workshop/a...agerollover/im
    > agerollover.asp
    > >
    > > However, even their own sample works 'intermitantly' sometimes sending

    a
    > request,
    > > sometimes not...
    > >
    > > --
    > > LFS (serflaten@usinternet.com)
    > > President - ChildsPlay Software Services
    > >
    > >
    > >
    > >

    >
    >



  12. #12
    Larry Serflaten Guest

    Re: How to cache images in VBScript?



    "Steve Cochran" <scochran@chattanooga.net> wrote in message news:3a06ddfb$1@news.devx.com...
    > Check out his article and the section on cache-control extensions and see if
    > that helps:
    >
    > http://msdn.microsoft.com/workshop/A...f/perftips.asp
    >
    > steve
    >


    Thanks Steve

    I did find that, and I did try the 'expires' meta tag, but its that post-check and pre-check
    cache-control properties that I need. Those apparently are only available on the server.

    I should have a few hours this week to try Avron's frame suggestion. I will post the results
    when I have them...

    --
    LFS (serflaten@usinternet.com)
    President - ChildsPlay Software Services





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center