reloading images : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

reloading images
In your browser hitting Reload should reload a page. However, it will often get an old version of an image, if that image’s expiry time has not past. You can force it to get a new image with Shift-Reload or Control-Reload.

It would be nice to be able to do the same thing with Applets, to let you load a new version of the Applet when you are debugging, but I have found only exiting and restarting the browser works. This is because the underlying JVM (Java Virtual Machine) is not designed to let you unload or replace class files. You can get the effect programmatically by using a new ClassLoader. Then you may have both versions of the class in RAM (Random Access Memory).

In Java programming, the URLConnection.setUseCaches( false)) can force reloading. I have not yet found a simple way to force Toolkit.getDefaultToolkit().getImage( url ) to get a fresh copy. I found that Image.flush does not work. It seems to flush only the Image cache, not other intermediate sources.

Here is a clever dodge dreamed up by Jonathan Bartlett to bypassing various caches to force a reload of an image. If you are reloading images from the web, you can randomize the URL (Uniform Resource Locator) to force reloads. So, if your url is http://www.example.com/image.gif, you could do something like http://www.example.com/image.gif?forcereload=23424, where 23424 is a randomly generated number, or generated by the current time, or something like that. Since it’s a different URL, any cache between you and the server has to reload, except at the server itself which will just ignore the extra dummy parameter.


This page is posted
on the web at:

http://mindprod.com/jgloss/reloadimage.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\reloadimage.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
no blog for this page
IP:[65.110.21.43]
Your face IP:[174.129.92.127]
You are visitor number