Author | Message | Time |
---|---|---|
Grok | Using Javascript, I want to retrieve an image from the server to the local cache, and store the absolute path to the local cache file (temporary internet files) in a Javascript variable. I looked in the image rollover techniques documentation thinking they would typically prefetch an array of images to speed performance. The prefetch technique was not documented. Anyone know this technique and can show me some sample code for it? Note that I am NOT interested in mouse rollover techniques. I AM interested in prefetching an image prior to displaying it. Thanks, Grok | March 7, 2004, 5:56 AM |
Adron | Is this at all possible? I suppose allowing javascript in a browser to access your hard drive might be a security setting, but it's not obvious to me. | March 7, 2004, 4:40 PM |
Kp | Prefetching the image is pretty easy to do IIRC. However, like Adron, I don't know if you can actually find out what the browser has done with it afterward. My experience is limited to having the browser load up the images in preparation for a mouseover or timed auto-rotate. I've never checked (or, prior to now, cared) whether the browser caches the prefetched data and if so whether it caches in memory or on disk. If you're still interested in the prefetch with these limitations, I can dig up a sample document. | March 7, 2004, 5:00 PM |
Grok | [quote author=Adron link=board=22;threadid=5642;start=0#msg48068 date=1078677619] Is this at all possible? I suppose allowing javascript in a browser to access your hard drive might be a security setting, but it's not obvious to me. [/quote] This application uses an ActiveX control on the client browser. Since ActiveX controls are inherently insecure and ignore all rules of browser security, it can access the hard drive on the user's system. If I can figure out how to address the cached images by environment variable and filename, it will ease working with the images. Something like ActiveX.FileName = "%internet_cache%/imagefilename.tif". | March 7, 2004, 5:11 PM |
Grok | [quote author=Kp link=board=22;threadid=5642;start=0#msg48069 date=1078678854] Prefetching the image is pretty easy to do IIRC. However, like Adron, I don't know if you can actually find out what the browser has done with it afterward. My experience is limited to having the browser load up the images in preparation for a mouseover or timed auto-rotate. I've never checked (or, prior to now, cared) whether the browser caches the prefetched data and if so whether it caches in memory or on disk. If you're still interested in the prefetch with these limitations, I can dig up a sample document. [/quote] Yes, I am. I found examples that supposedly prefetch by loading an array with image urls, but I really don't see how an array of strings { "domain/filename1.gif", "domain/filename2.gif" .. } will cause the images to load to the cache. So those examples were probably wrong. I also would like to learn how to set the expires mode on individual images, if possible. The question is for work, but think about Skywing's webchannel. The icons are downloaded from vl.com every page refresh. By answering the previous questions, we could have webchannel do the same (precache the 12 or so images) and significantly reduce traffic for webchannel. | March 7, 2004, 5:14 PM |
Kp | [quote author=Grok link=board=22;threadid=5642;start=0#msg48070 date=1078679470]If I can figure out how to address the cached images by environment variable and filename, it will ease working with the images. Something like ActiveX.FileName = "%internet_cache%/imagefilename.tif".[/quote] Try "%USERPROFILE%/Local Settings/Temporary Internet Files"? This seems to be where my IE cache lives (even though I don't use IE, you said earlier all your viewers will be using it). [quote author=Grok link=board=22;threadid=5642;start=0#msg48071 date=1078679692]Yes, I am. I found examples that supposedly prefetch by loading an array with image urls, but I really don't see how an array of strings { "domain/filename1.gif", "domain/filename2.gif" .. } will cause the images to load to the cache.[/quote] This is some fairly old JavaScript, but it should still work: [code]var images = new Array(4); images[0] = new Image (x_width, y_width); images[0].src = "http://www.valhallalegends.com/images/vl2black.jpg"; /* or whatever image you want */ images[1] = new Image (x_width, y_width); /* etc. */ [/code]You could just as easily have many unique variables instead of an array of images, but IMO this approach is cleaner. I stopped using it because my browser at the time (Netscape 4) seemed to degrade rapidly if the page was refreshed (though I had many more than 4 images pre-fetched in this way). My guess is that its garbage collection was buggy, leading to extra copies of the image in memory. [quote author=Grok link=board=22;threadid=5642;start=0#msg48071 date=1078679692]I also would like to learn how to set the expires mode on individual images, if possible. The question is for work, but think about Skywing's webchannel. The icons are downloaded from vl.com every page refresh. By answering the previous questions, we could have webchannel do the same (precache the 12 or so images) and significantly reduce traffic for webchannel.[/quote] I don't know how to do this, and the prefetch method I had in mind doesn't seem to keep the data cached across page reloads (but keep in mind all my testing was done on Netscape, and IE might behave differently). | March 7, 2004, 5:37 PM |
Grok | Thanks for the above. I will try it out for my application. [quote author=Kp link=board=22;threadid=5642;start=0#msg48074 date=1078681049]I don't know how to do this, and the prefetch method I had in mind doesn't seem to keep the data cached across page reloads (but keep in mind all my testing was done on Netscape, and IE might behave differently).[/quote] This method you posted can easily be done in WebChannel, by creating a parent frame that does not reload. The parent frame would contain the image array, and the child frame would be able to reload freely, displaying images by way of document.parent.images[n].src. | March 7, 2004, 6:01 PM |
Kp | [quote author=Grok link=board=22;threadid=5642;start=0#msg48084 date=1078682488]This method you posted can easily be done in WebChannel, by creating a parent frame that does not reload. The parent frame would contain the image array, and the child frame would be able to reload freely, displaying images by way of document.parent.images[n].src.[/quote] I hadn't come up with a good way to do that and not mess with the layout, so I'd rejected that idea and not mentioned it. :) | March 7, 2004, 6:04 PM |
Grok | We discussed the WebChannel page at work, and decided it could try an invisible 1-pixel high parent frame with the remainder of the screen being everything else. The parent frame could contain the image cache, and not refresh, while the child frame is everything that WebChannel is currently. Adjust the child frame to get its image.src from the parent's image array. Hope I said this adequately, the experienced guys here said it will work. | March 7, 2004, 6:12 PM |
Kp | Makes sense to me, but it'll cause a nuisance for those of us who use frame-free browsers! | March 7, 2004, 7:11 PM |
Grok | [quote author=Kp link=board=22;threadid=5642;start=0#msg48109 date=1078686706] Makes sense to me, but it'll cause a nuisance for those of us who use frame-free browsers! [/quote] Code could detect the support of frames, and send the frameless page for people wishing that support. | March 7, 2004, 7:29 PM |
St0rm.iD | Applet? | March 8, 2004, 2:57 AM |
Grok | Client side? Would require everyone load some ewwy JVM. Yes? | March 8, 2004, 3:25 AM |
St0rm.iD | No, JVMs are already loaded on most machines. | March 10, 2004, 12:45 AM |
Kp | [quote author=St0rm.iD link=board=22;threadid=5642;start=0#msg48631 date=1078879501]No, JVMs are already loaded on most machines.[/quote] Pretty sure Java doesn't work at all in any of the browsers I use regularly. :) | March 10, 2004, 12:47 AM |
St0rm.iD | Doesn't mean it isn't loaded on most workstations/home PCs browsing the internet. | March 10, 2004, 1:06 AM |