reloading images : Java Glossary

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.


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/reloadimage.html J:\mindprod\jgloss\reloadimage.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.210]
You are visitor number 15,358.