I have this code on an applet. The applet works ok, but I get a lot of unnecessary duplicate download. In particular, I have noticed that each ‘getResource’ triggers a download of the .JAR file.
static { ac = new ImageIcon(MyClass.class.getResource('images/ac.png')).getImage(); dc = new ImageIcon(MyClass.class.getResource('images/dc.png')).getImage(); //...other images }
How can this be avoided?
Do you include the applet to a HTML page? If so, try to enable the JAR caching, as is described here: http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/applet_caching.html
If that does not help for some reason 🙂 perhaps expose your resources / images along your applet JAR on a web server and reach them using separate HTTP requests (yes, its ugly and yes, it does not reduce number of needed downloads, but it at least reduces the amount of data that need to be transferred).