Monday, April 16, 2012

Java 7: Reduce Applet Loading time using JNLP

Prior to Java 7, the JNLP file has to be downloaded first from the network before the applet can be launched. But with Java 7, the JNLP file can be embedded directly into the HTML code which reduces the amount of time the applet loading time. Following are the steps to embed a JNLP file:
  1. Create a JNLP file for your applet.
  2. Encode the contents of the JNLP file using the Base64 scheme.
  3. When deploying the applet in a web page, specify the 'jnlp_embedded parameter' with it's value set to the Base64 encoded JNLP string.
Example:
<script>
    var attributes = {} ;
    <!-- Base64 encoded string truncated below for readability -->
    var parameters = {jnlp_href: 'xyz-applet.jnlp',
        jnlp_embedded: 'PCEtLSAKLyoKICogQ29weXRSSDSDSD+-Dgkhmnwrr ...'
    } ;
    deployJava.runApplet(attributes, parameters, '1.6');
</script>
Note: Some encoding tools may wrap the encoded string into several 76-column lines. To use this multi-line attribute value in JavaScript code, specify the attribute value as a set of concatenated strings.

No comments: