Applet Caching

For an enhanced user experience the applet's startup time should be kept to a minimum.

The SignLive! CC cloud suite applets are delivered in compressed form (pack.gz) to minimize the download time. To effectively reduce the startup time, however, you should use Java plugin caching. Especially starting with Java 7 Update 25 where every jar file's signature certificate's validity is checked with OCSP by default.

To utilize Java caching the HTTP caching headers must be set correctly by your web server.
The goal is to set the HTTP headers Cache-Control and Expires to the largest values that are still acceptable with your security concept.

For example:
The JNLP file defining the applet should be loaded daily, so the content (parameters, jars) can be adapted any time.
The jar or jar.pack.gz files, which contain a version string in their name, should preferably be loaded only once. So the Cache-Control: max-age could be as long as we dare. A month or even a year are conceivable values.

Any code changes in the applet are delivered with new version numbers in the jar names. So only the JNLP file must be adapted to load the new jars. The JNLP file is loaded daily, so we can deliver new code to the client daily.

As an alternative you can add a version string to all your static resources like the JNLP files and increase their max-age settings. New versions are delivered then by referencing a new version in the HTML page.

Web Server Configuration Examples

Apache Tomcat 7

Apache Tomcat 7 uses a filter to set the Cache-Control headers.
The documentation can be found in Expires Filter.
To configure the example above, the WEB-INF/web.xml must contain the following snippet:

<filter>
   <filter-name>AppletExpiresFilter</filter-name>
   <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>

   <init-param>
      <param-name>ExpiresDefault</param-name>
      <param-value>access plus 1 month</param-value>
   </init-param>

   <init-param>
      <param-name>ExpiresByType application/x-java-jnlp-file</param-name>
      <param-value>access plus 12 hours</param-value>
   </init-param>
</filter>

<filter-mapping>
   <filter-name>AppletExpiresFilter</filter-name>
   <url-pattern>/CloudSuiteApplet/*</url-pattern>
   <dispatcher>REQUEST</dispatcher>
</filter-mapping>

The ExpiresDefault entry will set the Cache-Control: max-age header to a month after the request time.
For the JNLP file we set the Cache-Control: max-age 12 hours after the request, so it will be reloaded no later than the next day.

If successfully applied the startup of an applet will result in only 4 requests.
One request for the JNLP file:

"GET /cloudsuite-snippets/CloudSuiteApplet/import.jnlp HTTP/1.1" 200 1792
Three requests are issued by the applet itself:
"HEAD /cloudsuite-snippets/CloudSuiteApplet/extensions/override.args HTTP/1.1" 404 -
"HEAD /cloudsuite-snippets/CloudSuiteApplet/extensions/licenses/license.lic HTTP/1.1" 200 -
"HEAD /cloudsuite-snippets/CloudSuiteApplet/extensions/truststore.keystore HTTP/1.1" 404 -

Everything else is loaded from the local cache.

Apache HTTP Server Version 2.2

The Apache HTTP server uses the expires_module to set Expires HTTP header and the max-age directive of the Cache-Control HTTP header in the server response. See Apache Module mod_expires for details.

First of all you have to load the expires_module in your apache2.conf. The exact configuration depends on your operating system.

On a Debian Wheezy system, for example, you have to add a symbolic link from /etc/apache2/mods-available/expires.load to /etc/apache2/mods-enabled/expires.load . Or use a2enmod expire .

If you have an Apache2 build from source, you would add a LoadModule directive somewhere in your apache2.conf file.

LoadModule expires_module modules/mod_expires.so

The Expires HTTP header and the max-age directive for the applet are configured in either a central configuration file or a .htaccess file.

One of many ways to configure caching on a Debian system is to create a expires.conf file in the directory /etc/apache2/mods-available/ and add a symbolic link to it in the /etc/apache2/mods-enabled directory.
Inside that file you specify, what files should be cached. Example:

<IfModule mod_expires.c>
# all files end with jar, pack.gz or jnlp
<FilesMatch "\.(jar|pack\.gz|jnlp)$">
  # enable expirations  
  ExpiresActive On
  # jar, pack.gz
  ExpiresDefault "access plus 1 month"
  # JNLP files
  ExpiresByType application/x-java-jnlp-file "access plus 12 hours"
</FilesMatch>
</IfModule>

As an alternative, you could create a .htaccess file inside your applet directory with the following content:

# enable expirations
ExpiresActive On
# jar, png, etc.
ExpiresDefault "access plus 1 month"
# JNLP files
ExpiresByType application/x-java-jnlp-file "access plus 12 hours"
This would turn on caching just for this directory.
If this doesn't work immediately, check if .htaccess file is allowed to override mod_expire settings.
See AllowOverride Directive.